Common Salesforce Apex Errors

Common Exceptions in System Namespace

  1. System.AsyncException - Any problem with an asynchronous operation.
    1. Future method cannot be called from a future or batch method
    2. The Apex job named already scheduled for execution
  2. System.CalloutException - Any problem with a Web service operation.
    1. Exceeded maximum time allotted for callout
    2. Read timed out
  3. System.DmlException - Any problem with a DML statement on a record.
    1. CANNOT_EXECUTE_FLOW_TRIGGER
    2. FIELD_INTEGRITY_EXCEPTION
    3. INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY
    4. INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST
    5. MIXED_DML_OPERATION
    6. RECORD_IN_USE_BY_WORKFLOW
    7. REQUIRED_FIELD_MISSING
    8. STRING_TOO_LONG
    9. TRANSFER_REQUIRES_READ
    10. UNAVAILABLE_RECORDTYPE_EXCEPTION
    11. UNABLE_TO_LOCK_ROW
  4. System.EmailException - Any problem with email
  5. System.FinalException - Any attempt to mutate a read-only collection or record such as an sObject in an after-update trigger, or a final variable.
    1. SObject row does not allow errors
  6. System.FlowException - Any problem with starting flow interviews from Apex.
  7. System.JSONException - Any problem with JSON serialization and deserialization operations.
  8. System.LimitException - A governor limit has been exceeded.
    1. Too many DML rows: 10001
    2. Apex heap size too large
      1. Reason : Salesforce enforces an Apex Heap Size Limit of 6MB for synchronous transactions and 12MB for asynchronous transactions.
      2. Debug Process : Identify the collection variables used in the method throwing the error. Identify the SOQL queries in the method throwing the error
      3. Resolution : Deallocate space from the collection variable as soon as it’s not needed. Wherever possible, iterate over the results from the SOQL query rather than saving it in a collection variable and then iterating over it (Note : Ensure not to increase the count of SOQL in cases where result from a single SOQL query may be used at multiple places)
    3. Too many SOQL queries: 201
    4. Apex CPU time limit exceeded
  9. System.ListException - Any problem with a list.
    1. List index out of bounds
  10. System.NullPointerException - Any problem with dereferencing null
    1. Attempt to de-reference a null object
    2. Argument cannot be null.
  11. System.QueryException - Any problem with SOQL queries.
    1. Non-selective query against large object type
    2. Aggregate query has too many rows for direct assignment, use FOR loop
    3. List has no rows for assignment to SObject
  12. System.SObjectException - Any problem with sObject records.
    1. Field is not writeable
  13. System.StringException - Any problem with Strings,
  14. System.TypeException - Any problem with type conversions.

Reference : https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_exception_methods.htm

Receive my updates

Email me on neha.kumari@hey.com, or follow me via RSS, Twitter or Instagram.