In depth view of the governor limits in apex SalesForce
                                           SHIVANATH.D
What are Governor Limits ?
• Runtime limits enforced by apex
• Ensures no monopoly in resources.
                                      Memory
• Similar to heap size in Java.
• Back bone of MULTI-TENANT
architecture.                         Database Resources
• The Organization Shares the limit
                                      No of Script Statements


                                      No of Records processed
How are Governor Limits Calculated?
There are a number of factors that
determine what governor limit is
used, and when it is applied
                                     Invocation of Apex-Entry


                                     How Many Records


                                     Which Governor Limit
Entry Point
• Governor limits are applied based
on the entry point                       Apex Trigger
•insert, update, delete, merge,
upsert, and undelete are the Trigger
                                         Apex Web service
operations
• All Apex triggers are bulk triggers.
• Batch of up to 200 records             Anonymous Block
• Anonymous block does not get
stored in the metadata                   Visualforce Controller
•Run Tests is a Force.com Web
Services API call used to execute test
methods                                  Run Tests
Governor Limit Scope
• Governor Limits are shared by the
organization
                                         Maximum of 100 SOQL Queries
•From beginning till end of
execution
                                         Max of 50,000rows retrieved
•Governor limits are not specified for
each separate trigger.                   Max of 200,000 scripts executed
•Any Apex class, method, or trigger
invoked by code executed within the      Max 50 million Batch SOQL
entry point will count towards the
same governor limits as it's a           Batches of up to 2,000 records
synchronous request
Synchronous vsAsynchronous Apex
• Normal Execution Synchronous
•@future is asynchronous
                                 Synchronous
•Business Logic is offloaded
•Efficiency increases
• but , more callouts
                                     VS


                                 Asynchronous
Limits
SOQL statements issued in a request.
Database.countQuery
Database.getQueryLocator
Database.query
DML queries issued in a request.
Approval.process
Database.convertLead
Database.emptyRecycleBin
Database.rollback
Database.setSavePoint
delete and Database.delete
insert and Database.insert
merge
undelete and Database.undelete
update and Database.update
upsert and Database.upsert
System.runAs
Bulkify your Code
Poorly Written Code




Bulkified Code
Avoid SOQL Queries inside FOR Loops
Avoid SOQL Queries inside FOR Loops
Use Collections in code
Streamlining Multiple Triggers on the
Same Object

           • Merge if triggers are redundant
              • Triggers same share limit
            • Easy to hit the governor limits
Querying Large Data Sets
Use @futureAppropriately




Don’t do this !
Q &A

Governor limits

  • 1.
    In depth viewof the governor limits in apex SalesForce SHIVANATH.D
  • 2.
    What are GovernorLimits ? • Runtime limits enforced by apex • Ensures no monopoly in resources. Memory • Similar to heap size in Java. • Back bone of MULTI-TENANT architecture. Database Resources • The Organization Shares the limit No of Script Statements No of Records processed
  • 3.
    How are GovernorLimits Calculated? There are a number of factors that determine what governor limit is used, and when it is applied Invocation of Apex-Entry How Many Records Which Governor Limit
  • 4.
    Entry Point • Governorlimits are applied based on the entry point Apex Trigger •insert, update, delete, merge, upsert, and undelete are the Trigger Apex Web service operations • All Apex triggers are bulk triggers. • Batch of up to 200 records Anonymous Block • Anonymous block does not get stored in the metadata Visualforce Controller •Run Tests is a Force.com Web Services API call used to execute test methods Run Tests
  • 5.
    Governor Limit Scope •Governor Limits are shared by the organization Maximum of 100 SOQL Queries •From beginning till end of execution Max of 50,000rows retrieved •Governor limits are not specified for each separate trigger. Max of 200,000 scripts executed •Any Apex class, method, or trigger invoked by code executed within the Max 50 million Batch SOQL entry point will count towards the same governor limits as it's a Batches of up to 2,000 records synchronous request
  • 6.
    Synchronous vsAsynchronous Apex •Normal Execution Synchronous •@future is asynchronous Synchronous •Business Logic is offloaded •Efficiency increases • but , more callouts VS Asynchronous
  • 8.
    Limits SOQL statements issuedin a request. Database.countQuery Database.getQueryLocator Database.query DML queries issued in a request. Approval.process Database.convertLead Database.emptyRecycleBin Database.rollback Database.setSavePoint delete and Database.delete insert and Database.insert merge undelete and Database.undelete update and Database.update upsert and Database.upsert System.runAs
  • 9.
    Bulkify your Code PoorlyWritten Code Bulkified Code
  • 10.
    Avoid SOQL Queriesinside FOR Loops
  • 11.
    Avoid SOQL Queriesinside FOR Loops
  • 12.
  • 13.
    Streamlining Multiple Triggerson the Same Object • Merge if triggers are redundant • Triggers same share limit • Easy to hit the governor limits
  • 14.
  • 15.
  • 16.