Wednesday, October 10, 2018

Governor limits in salesforce

Why governor limits?

Governor limits are enforced to ensure that code runs correctly without any error. Governor limits ensured that you write correct code considering best practices.



Governor limits in salesforce



Limits value:

SOQL queries per transaction.
==>100.(synchronous)
SOQL queries per transaction.
==>200(asynchronous)
Number of record retrieve by SOQL query ==>50000.
dml statements per transaction
==> 150
Number of records proceeds by dml statement.
==> 10000
Total number of SOSL query:
==>20
Number of record retrieve by SOSL Statement ==>2000
Number of future method call per Apex transaction.
==>50
Number of Apex jobs in queue.
==>50
Heap size limit.
==> 6 MB ( synchronous)
        12 MB ( asynchronous)



Note: Refer list for Loop vs soql for Loop article for example on heap size error.

SOQL List vs SOQL For Loop


How to avoid hitting governor limits in test method ?



  • Using Test.startTest() method.



Points to remember to avoid hitting governor limits:


Salesforce Governor Limits


1) Avoid writing for loop inside the method.

2)Use soql for Loop instead of a list for Loop.

3)use Test.startTest() method inside test method to reset governor limits.

4)Do not update setup objects like user role with other objects in the same transaction.


***********************************************************************************************************

TAGS:Governor limit in salesforce,Salesforce Governor Limits,how to handle governor limits in salesforce,how to overcome governor limits in salesforce,governor limit exception in salesforce.

***********************************************************************************************************

1 comment: