Governor limits

16
INTRODUCTION TO GOVERNOR LIMITS In depth view of the governor limits in apex SalesForce SHIVANATH.D

Transcript of Governor limits

Page 1: Governor limits

INTRODUCTION TO GOVERNOR LIMITSIn depth view of the governor limits in apex SalesForce

SHIVANATH.D

Page 2: Governor limits

What are Governor Limits ?

• Runtime limits enforced by apex

• Ensures no monopoly in resources.

• Similar to heap size in Java.

• Back bone of MULTI-TENANT architecture.

• The Organization Shares the limit

Memory

Database Resources

No of Script Statements

No of Records processed

Page 3: Governor limits

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

Page 4: Governor limits

Entry Point

• Governor limits are applied based on the entry point

•insert, update, delete, merge, upsert, and undelete are the Trigger operations

• All Apex triggers are bulk triggers.

• Batch of up to 200 records

• Anonymous block does not get stored in the metadata

•Run Tests is a Force.com Web Services API call used to execute test methods

Apex Trigger

Apex Web service

Anonymous Block

Visualforce Controller

Run Tests

Page 5: Governor limits

Governor Limit Scope

• Governor Limits are shared by the organization

•From beginning till end of execution

•Governor limits are not specified for each separate trigger.

•Any Apex class, method, or trigger invoked by code executed within the entry point will count towards the same governor limits as it's a synchronous request

Maximum of 100 SOQL Queries

Max of 50,000rows retrieved

Max of 200,000 scripts executed

Max 50 million Batch SOQL

Batches of up to 2,000 records

Page 6: Governor limits

Synchronous vs Asynchronous Apex• Normal Execution Synchronous

•@future is asynchronous

•Business Logic is offloaded

•Efficiency increases

• but , more callouts

Synchronous

V\S

Asynchronous

Page 7: Governor limits
Page 8: Governor limits

LimitsSOQL 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

Page 9: Governor limits

Bulkify your Code

Poorly Written Code

Bulkified Code

Page 10: Governor limits

Avoid SOQL Queries inside FOR Loops

Page 11: Governor limits

Avoid SOQL Queries inside FOR Loops

Page 12: Governor limits

Use Collections in code

Page 13: Governor limits

Streamlining Multiple Triggers on the Same Object

• Merge if triggers are redundant

• Triggers same share limit

• Easy to hit the governor limits

Page 14: Governor limits

Querying Large Data Sets

Page 15: Governor limits

Use @future Appropriately

Don’t do this !

Page 16: Governor limits

Q & A