Governor Limits


As you ma be aware that Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits to ensure that runaway Apex code or processes don’t monopolize shared resources. If some Apex code exceeds a limit, the associated governor issues a runtime exception that cannot be handled.

Some of the common governor limits are

Total number of SOQL queries issued 100
Total number of records retrieved by SOQL queries 50,000
Total number of SOSL queries issued 20
Total number of DML statements issued 150
Total number of sendEmail methods allowed 10

Limits Class
Contains methods that return limit information for specific resources.

Example:
System.debug(‘Total Number of SOQL Queries allowed in this apex code context: ‘ + Limits.getLimitQueries());


System.debug(‘Total Number of records that can be queried in this apex code context: ‘ + Limits.getLimitDmlRows());


System.debug(‘Total Number of DML statements allowed in this apex code context: ‘ + Limits.getLimitDmlStatements() );


System.debug(‘Total Number of script statements allowed in this apex code context: ‘ + Limits.getLimitScriptStatements());


System.debug(‘Total Number of SOQL Queries allowed in this apex code context: ‘ + Limits.getLimitQueries());
System.debug(‘Total Number of records that can be queried in this apex code context: ‘ + Limits.getLimitDmlRows());
System.debug(‘Total Number of DML statements allowed in this apex code context: ‘ + Limits.getLimitDmlStatements() );
System.debug(‘Total Number of script statements allowed in this apex code context: ‘ + Limits.getLimitScriptStatements());

Permanent link to this article: https://salesforcebuddy.com/2019/03/check-apex-limits/

Leave a Reply

Your email address will not be published.