Tag Archives: Apex

Programmatically Check the salesforce field properties

It is very common that we need to check the field properties of a salesforce object. If there are a large number of fields, it is very time consuming to click on each field one at a time from salesforce user interface.  The following Apex code demonstrates how to print the nullable properties of all the fields in the Account object. You can change it to other objects or print different field properties.

Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();

Map<String,Schema.SObjectField> M = r.fields.getMap();
for(String fieldName : M.keySet()){
Schema.SObjectField field = M.get(fieldName);
Schema.DescribeFieldResult F = field.getDescribe();
Boolean isFieldreq  = F.isNillable() ;
System.debug (fieldName + ‘ is null:  ‘ +  isFieldreq);

}

Salesforce rule and trigger execution order

Posted on

The following is the order salesforce logic is applied to a record.

  1. Old record loaded from database (or initialized for new inserts)
  2. New record values overwrite old values
  3. System Validation Rules
  4. All Apex before triggers (EE / UE only)
  5. Custom Validation Rules
  6. Record saved to database (but not committed)
  7. Record reloaded from database
  8. All Apex after triggers (EE / UE only)
  9. Assignment rules
  10. Auto-response rules
  11. Workflow rules
  12. Escalation rules
  13. Parent Rollup Summary Formula value updated (if present)
  14. Database commit
  15. Post-commit logic (sending email)

Additional notes:

There is no way to control the order of execution within each group above.

Workflow field updates that run based on an approval process or time-dependent action do not trigger any rules.

Formula fields do not execute in this way. They calculate and display their results real-time whenever the field is accessed in any way. So for example if a Workflow Rule uses a Formula Field in its criteria or formula, the formula field is evaluated when the Workflow Rule criteria is checked.