Tuesday, September 3, 2013

Listing Required Fields for an Object in Salesforce Using Apex Code

Sometimes it's desirable or necessary to get a list of all required fields for a particular Salesforce object, especially for subsequent processing in Apex. Instead of hard-coding this list, which is not sustainable or maintainable long-term, a better approach is to use Salesforce field describe results and the isNillable() method.

Below is sample code that demonstrates this approach, code that can be adapted for any standard or custom object.