Friday, August 19, 2011

State Management In Batch Apex in Salesforce



Each execution of a batch Apex job is considered a discrete transaction. For example, a batch Apex job that contains 1,000 records and is executed without the optional scope parameter is considered five transactions of 200 records each.

If you specify Database.Stateful in the class definition, you can maintain state across these transactions. This is useful for counting or summarizing records as they're processed. For example, suppose your job processed opportunity records. You could define a method in execute to aggregate totals of the opportunity amounts as they were processed.
If you do not specify Database.Stateful, all member variables in the interface methods are set back to their original values.
The following example summarizes a custom field total__c as the records are processed:


global class SummarizeAccountTotal implements Database.Batchable<sObject>, Database.Stateful{
global final String Query;
global integer Summary;
global SummarizeAccountTotal(String q){Query=q;
Summary = 0;
}

global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<sObject> scope){
for(sObject s : scope){Summary = Integer.valueOf(s.get('total__c'))+Summary;

}
}

global void finish(Database.BatchableContext BC){

}
}

83 comments:

  1. This technical post helps me to improve my skills set, thanks for this wonder article I expect your upcoming blog, so keep sharing...
    Cloud computing course in Chennai|cloud training in chennai

    ReplyDelete

  2. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.
    Advanced Selenium Training in Chennai

    ReplyDelete
  3. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

    RPA Training in Bangalore

    ReplyDelete
  4. You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
    python training in chennai | python training in bangalore

    python online training | python training in pune

    python training in chennai | python training in bangalore

    python training in tambaram |

    ReplyDelete
  5. Really great post, Thank you for sharing This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up!
    Big data training in Marathahalli
    Big data training in btm
    Big data training in Rajajinagar
    Big data training in bangalore

    ReplyDelete
  6. Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune
    Data science training in kalyan nagar
    selenium training in chennai

    ReplyDelete
  7. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Devops Training in Chennai

    Devops Training in Bangalore

    Devops Training in pune

    Devops training in tambaram
    Devops training in velachery

    ReplyDelete
  8. I appreciate that you produced this wonderful article to help us get more knowledge about this topic. I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!
    python training in chennai
    python training in chennai
    python training in Bangalore

    ReplyDelete
  9. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this
    python online training
    python training in OMR
    python training in tambaram
    python training in annanagar

    ReplyDelete
  10. Really you have done great job,There are may person searching about that now they will find enough resources by your post
    DevOps online Training

    ReplyDelete
  11. UiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
    ui path training in bangalore

    ReplyDelete
  12. Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete

  13. Howdy, would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 completely different web browsers, and I must say this blog loads a lot quicker than most. Can you suggest a good internet hosting provider at a reasonable price?
    Amazon Web Services Training in OMR , Chennai | Best AWS Training in OMR,Chennai
    Amazon Web Services Training in Tambaram, Chennai|Best AWS Training in Tambaram, Chennai

    ReplyDelete
  14. Please let me know if you’re looking for an author for your site. You have some great posts, and I think I would be a good asset.
    fire and safety course in chennai

    ReplyDelete
  15. My blog goes over a lot of the same topics as yours, and I believe we could greatly benefit from each other. If you happen to be interested, feel free to shoot me an e-mail.
    safety course in chennai

    ReplyDelete
  16. A really good post man, very thankful and hopeful that you will write many more posts like this one.
    Devops Training in Chennai | Devops Training Institute in Chennai

    ReplyDelete
  17. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    angularjs online training

    apache spark online training

    informatica mdm online training

    devops online training

    aws online training

    ReplyDelete
  18. This post is really nice and pretty good maintained.
    Python Course in Chennai

    ReplyDelete
  19. Pretty good post. This is a wonderful article, Given so much info in it, keep sharing.


    Data Science in Bangalore

    ReplyDelete
  20. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    date analytics certification training courses

    ReplyDelete
  21. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    Data Science Course

    ReplyDelete
  22. Attend The Python Training in Bangalore From ExcelR. Practical Python Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python Training in Bangalore.

    ReplyDelete
  23. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    Great post, Thanks for sharing.

    ReplyDelete
  24. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!
    Data Science Courses

    ReplyDelete
  25. http://deniace.blogspot.com/2017/02/final-exam-database-design-oracle.html

    ReplyDelete
  26. I love your article so much. Good job
    Participants who complete the assignments and projects will get the eligibility to take the online exam. Thorough preparation is required by the participants to crack the exam. ExcelR's faculty will do the necessary handholding. Mock papers and practice tests will be provided to the eligible participants which help them to successfully clear the examination.

    Excelr Solutions

    ReplyDelete

  27. Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.

    salesforce Training in Bangalore
    uipath Training in Bangalore
    blueprism Training in Bangalore

    ReplyDelete
  28. The article is so informative. This is more helpful. Thanks for sharing.
    web design company in velachery

    ReplyDelete
  29. Interesting stuff to read. Keep it up.nice information for a new blogger…it is really helpful and this is very informative and intersting for those who are interested in blogging field.
    https://www.hindimei.net
    movierulz
    moviesrulz
    HandandPaw.co
    instagram-followers

    ReplyDelete
  30. Useful Information :

    Freshers Walkins provide information on all the job walkins happen in all over India. Popular IT Company jobs, Freshers walkins, java walkins, .net walkins @ http://fresherswalkins.co.in/

    ReplyDelete
  31. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    aws Training in Bangalore
    python Training in Bangalore
    hadoop Training in Bangalore
    angular js Training in Bangalore
    bigdata analytics Training in Bangalore

    ReplyDelete
  32. Vibe Yellowfin is a 10 foot 1 person recreational sit on top kayak that offers great stability. It is easy to transport SOT fishing kayak available out there.

    Emotion Spitfire SOT inflatable kayak

    ReplyDelete
  33. Very interesting, good job and thanks for sharing such a good blog. your article is so convincing that I never stop myself to say something about it. You’re doing a great job. Keep it up

    aws Training in Bangalore
    python Training in Bangalore
    hadoop Training in Bangalore
    angular js Training in Bangalore
    bigdata analytics Training in Bangalore

    ReplyDelete
  34. While suitable for most uses, these masks are not respirators! See our range of heavier duty particulate respirators if you need a product that conforms to EN149:2001 FFP1, FFP2 and FFP3D categories.

    3m dust masks


    ReplyDelete
  35. Als u zelf uw kind wil gaan helpen, moet u natuurlijk wel weten wat redactiesommen eigenlijk zijn. Bij redactiesommen zit de som verwerkt in een verhaal. Het worden dan ook wel verhaaltjessommen genoemd. Waar deze verhaaltjes eerst nog vrij eenvoudig en kort zijn, worden de redactiesommen in groep 8 steeds ingewikkelder.

    redactiesommen oefenen

    ReplyDelete
  36. Als je een partytent huurt is het belangrijk om ook aan de aankleding en inrichting te denken. Het is wel zo praktisch om dat ook bij Colors Events te regelen. Wij kunnen behalve jouw partytent ook zorgen voor meubilair zoals statafels, al dan niet voorzien van rokken, stoelen of gewone tafels. Ook feestverlichting mag niet ontbreken als je een feest in de avonduren organiseert

    Bezoek: colorsevents.nl

    ReplyDelete
  37. Webactueel schakel je in als je een maatwerk WordPress website laten maken wilt. Door een maatwerk website te ontwikkelen is het mogelijk om meer leads te genereren. Daarbij hebben we altijd oren voor de wensen en eisen die jij als ondernemer hebt als het om jouw website gaat. Bovendien gaat het om meer dan alleen een website. Ook het toepassen van de juist online marketingstrategie helpt hier in grote mate bij. Wij kunnen dit allemaal voor je verzorgen.

    Bekijk website

    ReplyDelete
  38. Really awesome blog!!! I finally found a great post here.I really enjoyed reading this article. Nice article on data science . Thanks for sharing your innovative ideas to our vision. Your writing style is simply awesome with useful information. Very informative, Excellent work! I will get back here.
    Data Science Course

    ReplyDelete
  39. Webactueel schakel je in als je een maatwerk WordPress website laten maken wilt. Door een maatwerk website te ontwikkelen is het mogelijk om meer leads te genereren. Daarbij hebben we altijd oren voor de wensen en eisen die jij als ondernemer hebt als het om jouw website gaat. Bovendien gaat het om meer dan alleen een website. Ook het toepassen van de juist online marketingstrategie helpt hier in grote mate bij. Wij kunnen dit allemaal voor je verzorgen.
    Lees meer

    ReplyDelete
  40. Excellent Blog! Great Work and informative.thanks for the information
    best digital marketing course mumbai

    ReplyDelete
  41. 우리카지노 100%안전 검증된 카지노사이트 만 엄선하여 소개해드립니다 국내 업계1위 우리카지노계열 전통이 있는 온라인카지노 에서 안전하고 편안한 게임을 ..
    우리카지노

    ReplyDelete
  42. It's late finding this act. At least, it's a thing to be familiar with that there are such events exist. I agree with your Blog and I will be back to inspect it more in the future so please keep up your act.
    data science course in malaysia
    data science certification
    data science course malaysia
    data science malaysia
    data scientist course malaysia

    ReplyDelete
  43. Excellent blog with lots of information, keep sharing. I am waiting for your more posts like this or related to any other informative topic.It is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog. Please, continue to give me such valuable posts. Data Science Training In Chennai | Certification | Data Science Courses in Chennai | Data Science Training In Bangalore | Certification | Data Science Courses in Bangalore | Data Science Training In Hyderabad | Certification | Data Science Courses in hyderabad | Data Science Training In Coimbatore | Certification | Data Science Courses in Coimbatore | Data Science Training | Certification | Data Science Online Training Course



    ReplyDelete
  44. Get to know about your credit options with us quickly! Its so easy, 2 more steps, call us. Personal broker for end to end hassle free loan processing. Get it done today!

    mortgage sydney

    ReplyDelete

  45. 100% Confirmed ✔️ Blue badge at Instagram

    No Login Password required | Only Profile Link / Username

    *Payment method: Bitcoin *

    Price : $1800 only!


    Requirements :

    🔹Half in advance
    🔸 14 working days to complete
    🔸 Government issued ID card

    Other Social Media ✔️ Verification services available also !!!

    Regards,
    The SmmGiant Team
    Skype: live:.cid.a97dbb194238e18c
    Email : smmgiant@gmail.com
    Panel: https://smmgiant.com

    ReplyDelete
  46. I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation. Thanks a lot for keeping great stuff. I am very much thankful for this site.
    data scientist certification

    ReplyDelete
  47. We understand that selling your home can be a difficult and confusing process, especially if you are in behind in your payments or have a home in need of repair. Our We Buy Houses investors can simplify the process by making you a clear, cash offer to purchase your home, along with presenting other options that may be available to you.
    We Buy Houses West Allis WI

    ReplyDelete
  48. pool cleaning service Get clean up your pool area with specialist clearing offerings business in an discount prices. Experienced understand how to fresh repair, matintenance and pool.

    swimming pool service near me

    ReplyDelete
  49. We understand that selling your home can be a difficult and confusing process, especially if you are in behind in your payments or have a home in need of repair. Our We Buy Houses investors can simplify the process by making you a clear, cash offer to purchase your home, along with presenting other options that may be available to you.

    We Buy Houses New Berlin WI

    ReplyDelete
  50. We buy houses in Columbia, SC. Need to sell your house fast in Columbia, SC? Simple Home Exits buys houses in Columbia, SC for cash. Contact us today!
    buy my house fast

    ReplyDelete
  51. The Highest Grad And Best Quality Rated commercial Bounce Houses
    nmy review here

    ReplyDelete
  52. Get Big Data Certification in Chennai for making your career as a shining sun with Infycle Technologies. Infycle Technologies is the best Big Data training institute in Chennai, providing complete hands-on practical training of professional specialists in the field. In addition to that, it also offers numerous programming language tutors in the software industry such as Oracle, Java, Python, AWS, Hadoop, etc. Once after the training, interviews will be arranged for the candidates, so that, they can set their career without any struggle. Of all that, 200% placement assurance will be given here. To have the best career, call 7502633633 to Infycle Technologies and grab a free demo to know more.Grab Big Data Certification in Chennai | Infycle Technologies

    ReplyDelete
  53. The article posted was very informative and useful. You people are doing a great job. Keep going.
    data science training

    ReplyDelete
  54. Set An Alert For USD TO INR FORECAST To Receive An Email When The Exchange Rate Changes. Alternatively, Bookmark The Page And Check Back Here Regularly.

    ReplyDelete
  55. AximTrade Review Offers A Safe And Secure Platform To Do Forex Trading And CFDs And Our Customer Support Is Ready To Help You 24/7. You Can Easily Sign Up Your Aximtrade Login Account Here.

    ReplyDelete
  56. this is really nice to read..informative post is very good to read..thanks a lot!
    data scientist training in malaysia

    ReplyDelete
  57. This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses.
    best data science training in hyderabad

    ReplyDelete
  58. Really awesome bog, informative blog and knowledgeable content. Thanks for sharing with us. If you want to become a data science expert, then check out the following link.
    Data Science Institute in Hyderabad

    ReplyDelete
  59. A great website with interesting and unique material what else would you need.
    full stack web development course

    ReplyDelete
  60. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
    data science training institute in hyderabad

    ReplyDelete
  61. Upon crime space hand including employee design low. Than senior choose include manager into form.religious

    ReplyDelete
  62. awesome post I want to express my gratitude for the time and work you put into making this informative and fascinating essay.
    Top CA Colleges in Hyderabad

    ReplyDelete