Governor Limits in Salesforce

Governor Limits in Salesforce

Governor Limits in Salesforce

Salesforce enforces Governor limits to ensure that resources are shared in multi-tenant environment. Developers need to be aware of the limits and understand how these governor limits will impact coding practices.

What are governor limits ?

  • Governor limits ensure that one customer does not monopolize shared resources in a multi-tenancy environment.
  • Examples of limits monitored are the amount of CPU time Used, memory used, how long a query can run ,how many records are returned from a query.
  • Limits are monitored per transaction and per customer over a defined time period to ensure that performance in one org is not impacted by another.

What is a Transaction?

A transaction is a code execution unit that is considered as one for monitoring governor limits.

Transactions may be initiated for triggers, web services, visualForce pages and cross multiple methods and triggers.

Let’s take an example to see what happens when we exceed governor limits.

[sourcecode lang=”java”]

for(integer x=0;x<200 ;x++)


Account newAcc=new Account(Name=’myAccount-‘+x);



insert newAcc;



catch(exception ex)


System.debug(‘Caught exception ‘);




//even if I add a new account

insert new Account(Name=’My Account-Deepika’);


Output of the above program:


  • The system enforces a DML limit of 150 statements per Apex transaction.
  • If there are more that 150 items, the 151st update call returns an exception that cannot be caught for exceeding the DML statement limit of 150.
  • No accounts will be inserted.


Important functions related to Governor Limits:

[sourcecode lang=”java”]

for(integer x=1;x<5 ;x++)


Account newAcc=new Account(Name=’MyTutorialRack-‘+x);



insert newAcc;


catch(exception ex)


System.debug(‘Caught exception ‘);




System.debug(‘Limits.getDmlStatements() ==>’+Limits.getDmlStatements());

System.debug(‘Limits.getDmlRows() ==>’+Limits.getDmlRows());

System.debug(‘Limits.getLimitDmlRows() ==>’+Limits.getLimitDmlRows());

System.debug(‘Limits.getLimitDmlStatements() ==>’+Limits.getLimitDmlStatements());


getDMLStatements() Returns the number of DML statements (such as insert, update) that have been called.

getLimitDMLStatements() Returns the total number of DML statements that can be called.

getDMLRows() counts the number of records that have been processed with any statement that counts against the DML limits.

Implications of Governor Limits on Transactions:

  • DML will be rolled back if governor limits are exceeded.
  • Best practices should be followed to avoid SOQL queries inside for loops.
  • For example, a SOQL query inside a loop may exceeded the maximum number of SOQL queries allowed
  • For processing of large number of records, Batch apex can be used.Batch apex breaks the record set down to smaller batches so governor limits are not reached

[sourcecode lang=”java”]
System.debug(‘Limit Aggregate: ‘+Limits.getLimitAggregateQueries());

System.debug(‘Limit Callout: ‘+Limits.getLimitCallouts());

System.debug(‘CPU Time: ‘+Limits.getLimitCpuTime());

System.debug(‘Limit DML Rows: ‘+Limits.getLimitDMLRows());

System.debug(‘Limit DML Statements: ‘+Limits.getLimitDMLStatements());

System.debug(‘Limit Email Invocation: ‘+Limits.getLimitEmailInvocations());

System.debug(‘Limit find similar call: ‘+Limits.getLimitFindSimilarCalls());

System.debug(‘Future calls: ‘+Limits.getLimitFutureCalls());

System.debug(‘Limit heap size: ‘+Limits.getLimitHeapSize());

System.debug(‘Limit queries: ‘+Limits.getLimitQueries());

System.debug(‘Limit SOSL Queries: ‘+Limits.getLimitSoslQueries());


Prepare for your Platform Developer 1 exam

References :To learn more

This Post Has 62 Comments

  1. Whitney

    I’m extremely impressed with your writing skills and also
    with the layout on your blog. Is this a paid theme or did you modify it yourself?
    Either way keep up the nice quality writing, it is rare
    to see a great blog like this one nowadays.

  2. I do not even know how I ended up here, but I thought this post was great.

    I don’t know who you are but certainly you’re going to a famous blogger if you aren’t already ;
    ) Cheers!

  3. lovesick hacks

    Hmm is anyone else having problems with the images on this blog
    loading? I’m trying to find out if its a problem on my end or
    if it’s the blog. Any responses would be greatly appreciated.

  4. I blog quite often and I genuinely appreciate your information.
    This article has truly peaked my interest. I am going to bookmark your site and
    keep checking for new details about once per week. I opted
    in for your RSS feed too.

  5. Sandy

    Every weekend i used to pay a quick visit this website,
    because i want enjoyment, since this this web site conations in fact nice funny data too.

  6. Ahaa, its good discussion regarding this piece of writing here at
    this website, I have read all that, so now me also commenting here.

  7. recommended site

    Simply desire to say your article is as astounding.
    The clarity on your publish is just spectacular and i
    could think you are knowledgeable on this subject. Fine along with your permission let me to snatch your RSS feed to stay updated with
    coming near near post. Thanks a million and please keep up the
    gratifying work.

  8. Annmarie

    I’ve been exploring for a little for any high-quality
    articles or blog posts on this kind of area . Exploring in Yahoo I ultimately stumbled upon this website.
    Studying this information So i’m satisfied to express that I have an incredibly just right uncanny feeling I came upon exactly what I needed.
    I most definitely will make certain to do not omit
    this website and give it a glance on a relentless basis.

  9. Dominique

    Howdy, I believe your blog could possibly be having internet browser compatibility issues.
    When I take a look at your site in Safari, it looks fine however, when opening in Internet Explorer,
    it’s got some overlapping issues. I simply wanted to provide you with a quick heads up!

    Other than that, wonderful blog!

  10. Junko

    Hello, i read your blog occasionally and i own a similar one and i was just
    wondering if you get a lot of spam comments? If so how do you stop it, any
    plugin or anything you can advise? I get so much lately it’s driving me
    crazy so any assistance is very much appreciated.

  11. Hi there are using WordPress for your site platform? I’m new to
    the blog world but I’m trying to get started and set up my
    own. Do you need any html coding knowledge to make your own blog?
    Any help would be really appreciated!

  12. Digital download

    It’s an remarkable paragraph for all the internet people; they will take benefit from
    it I am sure.

  13. Jens

    Hi there mates, how is everything, and what you would like to say on the
    topic of this post, in my view its genuinely amazing in support of me.

  14. I’ve been surfing online more than 4 hours today, yet I never found any interesting
    article like yours. It is pretty worth enough for me.

    In my view, if all site owners and bloggers made good content as you did, the web will be a lot more useful than ever before.

  15. relx hk

    This design is spectacular! You certainly
    know how to keep a reader entertained. Between your wit and your
    videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job.
    I really enjoyed what you had to say, and more than that, how you presented it.

    Too cool!

  16. lu main di platform apaan? klo di ps3 sama xbox 360 emg kaga
    ada udh ketinggalan jaman, yg ada cuma ps4, xbox1 sama pc

  17. Kandi

    I know this if off topic but I’m looking into starting my own weblog and was wondering what
    all is needed to get set up? I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very internet smart so I’m not 100% sure. Any suggestions or advice would be
    greatly appreciated. Cheers

  18. Coleman

    It’s awesome in support of me to have a web
    page, which is beneficial for my knowledge. thanks admin

  19. XMLTV epg

    Excellent blog here! Additionally your website so much up fast!
    What web host are you the use of? Can I get your affiliate link
    to your host? I want my site loaded up as fast as yours lol

  20. Adrienne

    If you want to grow your know-how just keep visiting this site and
    be updated with the latest news update posted

  21. If some one needs expert view about blogging after that i
    suggest him/her to visit this webpage, Keep up
    the pleasant job.

  22. XMLTV epg

    Hey there! Quick question that’s totally off topic.
    Do you know how to make your site mobile friendly?
    My weblog looks weird when browsing from my iphone 4.
    I’m trying to find a theme or plugin that might be able to resolve this problem.
    If you have any suggestions, please share. Many thanks!

  23. Erma

    I absolutely love your blog.. Great colors & theme.
    Did you develop this amazing site yourself?
    Please reply back as I’m hoping to create my own personal blog and would like to know where
    you got this from or what the theme is called. Kudos!

  24. Pearlene

    After going over a number of the blog posts on your blog, I really appreciate your technique
    of blogging. I saved it to my bookmark site list and will be checking back soon. Take a look at my web site too and let me know how you

  25. Trudi

    Thank you for the good writeup. It in fact was a amusement account it.
    Look advanced to far added agreeable from you! However, how
    could we communicate?

  26. Nathan

    Have you ever thought about adding a little bit more than just
    your articles? I mean, what you say is important
    and all. Nevertheless imagine if you added some great
    images or video clips to give your posts more, “pop”!
    Your content is excellent but with pics and video clips, this blog could undeniably be one of the most beneficial in its
    field. Excellent blog!

  27. asikqq

    Thanks on your marvelous posting! I seriously enjoyed reading it, you may be a great author.I
    will make certain to bookmark your blog and will come back down the road.
    I want to encourage yourself to continue your great job,
    have a nice morning!

  28. We stumbled over here coming from a different web address and thought I may
    as well check things out. I like what I see so i am just following you.
    Look forward to going over your web page repeatedly.

  29. This is my first time pay a visit at here and i am in fact
    impressed to read all at single place.

  30. It’s a shame you don’t have a donate button! I’d most certainly donate to this fantastic blog!
    I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will share this blog with my Facebook
    group. Talk soon!

  31. vertigo replica

    I must thank you for the efforts you’ve put in writing this blog.
    I’m hoping to see the same high-grade blog posts from you in the future as well.
    In truth, your creative writing abilities has motivated me to get my
    own, personal site now 😉

  32. Winegrowers

    Do you mind if I quote a couple of your articles
    as long as I provide credit and sources back to your blog?
    My blog is in the very same niche as yours and my
    users would definitely benefit from some of the information you provide here.
    Please let me know if this alright with you. Thank you!

  33. classifieds php

    Heya i’m for the first time here. I came across this
    board and I find It really useful & it helped me out a lot.
    I hope to give something back and aid others like you helped me.

  34. classifieds php

    If you desire to take a great deal from this article then you have to apply these techniques to your won blog.

  35. This excellent website certainly has all the information I needed about this subject and didn’t know
    who to ask.

  36. Good post. I learn something new and challenging on websites I
    stumbleupon on a daily basis. It’s always exciting to read content from other authors and practice something from their web sites.

  37. It’s going to be ending of mine day, except before ending I
    am reading this wonderful piece of writing to increase my knowledge.

  38. Genuinely no matter if someone doesn’t be aware of
    after that its up to other visitors that they will help, so
    here it takes place.

  39. xây nhà

    Valuable info. Lucky me I found your website by accident, and I’m stunned why this coincidence did not came
    about in advance! I bookmarked it.

  40. It is appropriate time to make some plans for the future and it is
    time to be happy. I have learn this put up and if I may just I want to
    recommend you few attention-grabbing issues or advice. Perhaps you can write
    next articles relating to this article. I desire to learn even more issues approximately

  41. Very good blog you have here but I was curious if you knew
    of any message boards that cover the same topics talked about here?
    I’d really love to be a part of community where I can get suggestions from other experienced individuals
    that share the same interest. If you have any suggestions, please let me know.

  42. Hi there, the whole thing is going sound here and ofcourse every one is sharing data, that’s really excellent,
    keep up writing.

  43. Abcya 300

    I am really loving the theme/design of your website.
    Do you ever run into any web browser compatibility problems?
    A small number of my blog audience have complained
    about my blog not operating correctly in Explorer but looks great in Firefox.
    Do you have any ideas to help fix this problem?

  44. nha thau xay dung

    Thank you for some other excellent article. The place else
    could anyone get that type of info in such an ideal way
    of writing? I’ve a presentation subsequent week, and I am on the search for such

  45. fantastic post, very informative. I ponder why the opposite specialists of this
    sector do not notice this. You must proceed your writing.
    I’m sure, you’ve a huge readers’ base already!

  46. Excellent post. I used to be checking continuously this weblog and I’m impressed!
    Very useful info specifically the final part 🙂 I care for such info a lot.
    I used to be looking for this particular info for a long time.
    Thank you and good luck.

  47. Hi! I know this is kind of off topic but I was wondering if you knew where I could get a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having difficulty finding
    one? Thanks a lot!

  48. I am in fact grateful to the holder of this web page who has shared this fantastic post at here.

  49. I read this piece of writing fully on the topic of the difference of most up-to-date and earlier
    technologies, it’s amazing article.

  50. We stumbled over here from a different web page and thought I should
    check things out. I like what I see so now i’m following you.
    Look forward to exploring your web page again.

Leave a Reply