Governor limits

Post on 11-May-2015

21.833 views 4 download

Tags:

Transcript of Governor limits

INTRODUCTION TO GOVERNOR LIMITSIn 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.

• 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

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

•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

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

Synchronous vs Asynchronous Apex• Normal Execution Synchronous

•@future is asynchronous

•Business Logic is offloaded

•Efficiency increases

• but , more callouts

Synchronous

V\S

Asynchronous

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

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 @future Appropriately

Don’t do this !

Q & A