function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sampath pallisampath palli 

what is Govering limits in salesforce.com? Why it is introduced in salesforce?

Best Answer chosen by sampath palli
Mahesh DMahesh D
Hi Sampath,

Governor limits are runtime limits enforced by the Apex runtime engine. Because Apex runs in a shared, multitenant environment, the Apex runtime engine strictly enforces a number of limits to ensure that code does not monopolize shared resources.

The Apex limits, or governors, track and enforce the statistics outlined in the following tables and sections.
  • Per-Transaction Apex Limits
  • Per-Transaction Certified Managed Package Limits
  • Force.com Platform Apex Limits
  • Static Apex Limits
  • Size-Specific Apex Limits
  • Miscellaneous Apex Limits
Please go through the below links for more information:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm

https://developer.salesforce.com/page/Governors_in_Apex_Code

http://www.sfdc99.com/2013/11/17/what-are-governor-limits/


If you see below code:
 
for(Contact con: Trigger.new) {
	Account acc = [Select Id, Name from Account where Id =: con.AccountId];
}

Here the SOQL query is inside the for loop, if we perform the Data Migration with 200 records, for each record the SOQL query will execute which will take lot of time to process and reserve lot of resources. Hence we have to write the below code to overcode those issues / limitations.
 
Set<Id> accIdSet = new Set<Id>();
for(Contact con: Trigger.new) {
	accIdSet.add(con.AccountId);
}

Map<Id,Account> accMap = new Map<Id, Account>([Select Id, Name from Account where Id IN: accIdSet]);

Please do let me know if it helps you.

Regards,
Mahesh

 

All Answers

BALAJI CHBALAJI CH
Hi Sampath,
  • Salesforce runs on multi-tenancy environment and in order to have same performance to the database, it has imposed some run time limits called Governor limits.
  • Apex is compiled and executed on the Force.com multitenant infrastructure, which is a shared resource across all customers, partners, and developers
  • Consequently, it is important that Apex code uses infrastructure resources efficiently.
  • Governor limits prevent other orgs from writing inefficient code and taking up all the cloud CPU
  • Governor limits are not intended to limit your Apex solutions or prevent you from writing rich, complete solutions.
  • Instead, they are enforced to ensure efficient and scalable code is executing on the Force.com platform in a shared, multitenant environment.
For more information, please find below links:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm
http://resources.docs.salesforce.com/200/19/en-us/sfdc/pdf/salesforce_app_limits_cheatsheet.pdf
https://www.youtube.com/watch?v=Xnf5-i1MG3Y

Best Regards,
BALAJI
Mahesh DMahesh D
Hi Sampath,

Governor limits are runtime limits enforced by the Apex runtime engine. Because Apex runs in a shared, multitenant environment, the Apex runtime engine strictly enforces a number of limits to ensure that code does not monopolize shared resources.

The Apex limits, or governors, track and enforce the statistics outlined in the following tables and sections.
  • Per-Transaction Apex Limits
  • Per-Transaction Certified Managed Package Limits
  • Force.com Platform Apex Limits
  • Static Apex Limits
  • Size-Specific Apex Limits
  • Miscellaneous Apex Limits
Please go through the below links for more information:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm

https://developer.salesforce.com/page/Governors_in_Apex_Code

http://www.sfdc99.com/2013/11/17/what-are-governor-limits/


If you see below code:
 
for(Contact con: Trigger.new) {
	Account acc = [Select Id, Name from Account where Id =: con.AccountId];
}

Here the SOQL query is inside the for loop, if we perform the Data Migration with 200 records, for each record the SOQL query will execute which will take lot of time to process and reserve lot of resources. Hence we have to write the below code to overcode those issues / limitations.
 
Set<Id> accIdSet = new Set<Id>();
for(Contact con: Trigger.new) {
	accIdSet.add(con.AccountId);
}

Map<Id,Account> accMap = new Map<Id, Account>([Select Id, Name from Account where Id IN: accIdSet]);

Please do let me know if it helps you.

Regards,
Mahesh

 
This was selected as the best answer
DeepthiDeepthi (Salesforce Developers) 
Hi Sampath,

Governor limits are runtime limits enforced by the Apex runtime engine. Because Apex runs in a shared, multitenant environment, the Apex runtime engine strictly enforces a number of limits to ensure that code does not monopolize shared resources. Types of limits that Apex enforces are resources like memory, database resources, number of script statements to avoid infinite loops, and number of records being processed. If code exceeds a limit, the associated governor issues a runtime exception that cannot be handled thereby terminating the request.

So why have governor limits? Multitenancy is one of the cornerstones of the Force.com platform that allows salesforce.com to ensure all customers are on the same version of the platform codebase, while providing the ability to customize their own environment. This allows customers, partners, and developers to share our infrastructure resources in a manner similar to how an apartment building shares it common area and facilities with all tenants. The benefit is a highly scalable infrastructure and platform that is equally shared across the entire user base. But to ensure that the server resources are not disproportionately used in an inefficient manner, Apex code has governor limits in place. Governor limits guarantee that no implementation of Apex will negatively impact other salesforce.com instances.

Also, check the below links for more reference:
https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm 

https://developer.salesforce.com/page/Governors_in_Apex_Code 

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm 

Hope this helps you!
Best Regards,
Deepthi
sampath pallisampath palli
thank U All Very Use Full Stuff