Pages

Tuesday, November 29, 2011

Sharing the Cloud, Part 2 - Governor Limits

Another way that SFDC makes the cloud more friendly is by using governor limits. By limiting the amount of resources consumed by a single tenant, SFDC can provide a standard level of service and reliability across its entire offering.  This post may create more questions than answers at this stage, but we will address more and more items as I add to this blog.


There are many kinds of governor limits in place but generally speaking I put them into categories:

  • Platform Limits
    • Work Flow and Approval limits
    • Sandbox limits
    • Refresh Limits
    • Characters of Code
  • Application Limits
    • Apex Limits
      • Quantity of queries
      • Quantity of query results
      • Cumulative SOQL statements invoked by a trigger fire
    • API limits
      • Number of API calls
    • Visualforce Limits
      • View State
    • SOQL and SOSL Limits
      • Relationship limits
      • Length of query statement
An excellent breakdown of the current limits can be found here at the Winter '12 Limits Cheat Sheet .

But what do all of these limits mean to us as developers?

It means we have to make out code as lean as possible to accomplish everything our clients need.

Some good practices include:
  • Design your Data well, with some forward looking when designing your data model. This higher Normal Form that you can maintain  the easier it will be to get the data that you want without anything additional to count against your limits while serving no real purpose.
  • Avoid putting DML statements inside of loops. You can add all of your DML statements to a list and insert the entire list all at once!
  • Judicial use of the "transient" keyword when creating variables that can not be saved can reduce your View state. 
    • Example:
      • transient boolean myBool;
  • Plan your queries ahead of time, and get all the data in one query. Once you have it you can reassign the same collection more than once.
Salesforce is my first Developer platform, and it has a lot of governor limits to be mindful of. At first glance I was daunted by what I perceived as a crippling cap on what I could do as a developer. Over time though I have come to appreciate the limits. I am making better decisions when creating my applications, I am putting pages and controllers together that do all they need and them move the user on to then next page or task. I have a greater understanding of the relationships in my data. But most importantly, I am writing better more effective code.

No comments:

Post a Comment