Sunday 4 May 2014

Limit Class and Limit Methods in Salesforce with Example

The Limits methods return the specific limit for the particular governor, such as the number of calls of a method or the amount of heap size remaining.
Because Apex runs in a multitenant environment, the Apex runtime engine strictly enforces a number of limits to ensure that runaway Apex doesn’t monopolize shared resources.
None of the Limits methods require an argument. The format of the limits methods is as follows:
myDMLLimit = Limits.getDMLStatements();
There are two versions of every method:
The first returns the amount of the resource that has been used while the second version contains the word limit and returns the total amount of the resource that is available.\

Example of second version methods:

  1. System.debug('Limit Aggregate'+System.limits.getLimitAggregateQueries());
  2.  
  3. System.debug('Limit Callout'+System.limits.getLimitCallouts());
  4.  
  5. System.debug('Limit Child Describe'+System.limits.getLimitChildRelationshipsDescribes());
  6.  
  7. System.debug('CPU Time'+System.limits.getLimitCpuTime());
  8.  
  9. System.debug('Limit DML Rows'+System.limits.getLimitDMLRows());
  10.  
  11. System.debug('Limit DML Statements'+System.limits.getLimitDMLStatements());
  12.  
  13. System.debug('Limit Email Invocation'+System.limits.getLimitEmailInvocations());
  14.  
  15. System.debug('Field Describe'+System.limits.getLimitFieldsDescribes());
  16.  
  17. System.debug('Field Set Describe'+System.limits.getLimitFieldSetsDescribes());
  18.  
  19. System.debug('Limit find similar call'+System.limits.getLimitFindSimilarCalls());
  20.  
  21. System.debug('Future calls'+System.limits.getLimitFutureCalls());
  22.  
  23. System.debug('Limit heap size'+System.limits.getLimitHeapSize());
  24.  
  25. System.debug('Limit queries'+System.limits.getLimitQueries());
  26.  
  27. System.debug('Picklist Describe'+System.limits.getLimitPicklistDescribes());
  28.  
  29. System.debug('Limit Query Locator'+System.limits.getLimitQueryLocatorRows());
  30.  
  31. System.debug('Limit Query Rows'+System.limits.getLimitQueryRows());
  32.  
  33. System.debug('Limit Record Types'+System.limits.getLimitRecordTypesDescribes());
  34.  
  35. System.debug('Limit RunAs'+System.limits.getLimitRunAs());
  36.  
  37. System.debug('Limit Save Point Rollback'+System.limits.getLimitSavepointRollbacks());
  38.  
  39. System.debug('Limit Save Point'+System.limits.getLimitSavepoints());
  40.  
  41. System.debug('Limit Script Methods'+System.limits.getLimitScriptStatements());
  42.  
  43. System.debug('Limit SOSL Queries'+System.limits.getLimitSoslQueries());







For more details refer http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_limits.htm

No comments:

Post a Comment

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...