Friday 6 July 2012

Rule your Apex Governor Limits through actionFunction


Recently I ran into an issue where I had to make more than 10 HTTP Callouts from my Apex code. Immediate solution we would think would be batch apex or future calls, but this was not a great idea as user would have to wait till the whole process is complete and also due to the number of apex job limits.

Finally we came up this solution – use actionFunction and split Apex callouts. Since Limit of 10 API Callouts is for single execution, we can always make multiple executes with smaller number of callouts. For example – If originally I had to make 20 callouts on click of a button, What if I click 4 different buttons with 5 Callouts each – We will not hit the Limit here…!

Here is the sample code for the same.

/*
Controller for Demo Page
*/
public with sharing class DemoPageControler {

//Declare vars...
List objAccounts;
public String currentStatus {get;set;}

//Constructor
public DemoPageControler(){

objAccounts = new List();
}

//main method...
public void processRecords(){
//This method when called will throw exception
process1();
process2();
process3();
process4();
}

public void process1(){

//This function makes 5 Callouts
callHTTP();
callHTTP();
callHTTP();
callHTTP();
callHTTP();

currentStatus = 'Process 1 completed';
}

public void process2(){


//This function makes 5 Callouts
callHTTP();
callHTTP();
callHTTP();
callHTTP();
callHTTP();

currentStatus = 'Process 2 completed';
}

public void process3(){

//This function makes 5 Callouts
callHTTP();
callHTTP();
callHTTP();
callHTTP();
callHTTP();

currentStatus = 'Process 3 completed';
}

public void process4(){

//This function makes 5 Callouts
callHTTP();
callHTTP();
callHTTP();
callHTTP();
callHTTP();

currentStatus = 'Process completed';
}

public void blankFunction(){


}

public void callHTTP() {

String strurl='http://maps.googleapis.com/maps/api/geocode/xml?address=92618&sensor=false';
HttpRequest req=new HttpRequest();
req.setEndpoint(strurl);
req.setMethod('POST');
string strbody='hi';
req.setBody(strbody);
req.setCompressed(true);
Http http=new Http();
HTTPResponse res=http.send(req);
string strRes=res.getbody();
system.debug('**** Response XML Data is *****'+strRes);

}
}



VisualForce Page code:























We can use the same process to get around other similar exceptions like too many DML operations, too many script statements.

 

49 comments:

  1. Cloud is one of the tremendous technology that any company in this world would rely on(Salesforce Training institutes in Chennai). Using this technology many tough tasks can be accomplished easily in no time. Your content are also explaining the same(Salesforce developer training in chennai). Thanks for sharing this in here. You are running a great blog, keep up this good work(big data training).

    ReplyDelete
  2. Hi admin,
    I went through your article and it’s loaded with awesome information. You can consider including RSS feed. So that, I can get your latest update direct to my inbox.
    Java Training in Chennai
    .Net Training in Chennai
    PHP Training in Chennai

    ReplyDelete
  3. Thanks for sharing this niche useful informative post to our knowledge, Actually SAP is ERP software that can be used in many companies for their day to day business activities it has great scope in future.
    Regards,
    SAP Training in Chennai|SAP Course in Chennai|SAP Training|SAP training in chennai

    ReplyDelete
  4. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    Regards,
    Python Training in Chennai|Python Courses in Chennai

    ReplyDelete
  5. Awesome Post! I like writing style, how you describing the topics throughout the post. I hope many web reader will keep reading your post at the end, Thanks for sharing your view.
    Regards,
    SAP training in chennai|SAP courses in chennai|
    SAP Training in Chennai|sap training in Chennai

    ReplyDelete
  6. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me understand through this article. You have done a great job by sharing this content in here. Keep writing article like this.

    DOT NET Training in Chennai | DOT NET Course in Chennai | DOT NET Training Institutes in Chennai

    ReplyDelete
  7. PHP scripting is definitely one of the easiest, if not the easiest scripting language to learn and grasp for developers. This is partially due to the similarities PHP syntax has with C and Java. Even if the only knowledge of development that you have is with HTML, picking up PHP is still fairly easy.
    PHP training in Chennai|PHP training institute in Chennai|PHP course in Chennai

    ReplyDelete
  8. Learning new technolgoy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.

    Best JAVA Training institute in Chennai | Best JAVA Training in Chennai | Hadoop training in chennai

    ReplyDelete
  9. Contact us for website service and much more......

    Android Application Development

    ReplyDelete
  10. This blog is impressive and informative.It clearly explains about the concept and its
    techniques.Thanks for sharing this information.Please update this type of
    information
    Php Training in Chennai

    ReplyDelete
  11. Glad to see your blog post. This was very informative. I gained more knowledge by obtaining the limited amount of apex. Thanks a lot for sharing this information with us.

    Dotnet Training in Chennai

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Great blog..You have clearly explained about the conept..Step by step explaination is too good to understnad..Its very useful for me to undertand..Keep on sharing..
    Hadoop training in chennai

    ReplyDelete
  14. wonderful coding. this is very helpful to us.great doing. and i happy to visit your blog to know about this wonderful information. thanks for sharing. keep updating.
    Salesforce Training in Chennai

    ReplyDelete
  15. great doing. and i happy to visit your blog to know about this wonderful information. thanks for sharing. keep updating.
    ccna Training in Chennai

    ReplyDelete
  16. Awesome..You have clearly explained ...Its very useful for me to know about new things..Keep on blogging..
    Java Training in Chennai

    ReplyDelete
  17. We are offering website designing and web development..:) Web Official Blog

    ReplyDelete
  18. thanks for sharing wonderful information with us. i found your article is more useful and impressive. keep doing like this.
    Software Testing Training in Chennai

    ReplyDelete
  19. This blog gives the details about the job offers. This is very useful for job searchers. Here this blog helps to know about the job details. Thanks for this informative blog.
    PHP Training in Chennai

    ReplyDelete


  20. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.


    SAP training in Chennai

    ReplyDelete
  21. These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post. Your articles really impressed for me,because of all information so nice.

    SAP training in Chennai

    ReplyDelete

  22. I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.

    SAP training in Chennai

    ReplyDelete

  23. I read your articles very excellent and the i agree our all points because all is very good information provided this through in the post. It is very helpful for me. Keep blogging like this. Thanks.


    SAP training in Chennai

    ReplyDelete
  24. Good post. I learn something totally new and challenging on blogs I stumble upon on a daily basis. It will always be interesting to read articles from other authors and practice something from their websites...

    Digital marketing company in Chennai

    ReplyDelete
  25. Pleasant Post. It is truly intriguing to peruse from the earliest starting point and I might want to share your site to my circles, continue sharing more like this.
    Regards,
    ccna institutes in Chennai | ccna Training center in Chennai | ccna Training in Chennai | ccna course in Chennai

    ReplyDelete
  26. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Web Designing Course in Chennai | web designing training in chennai

    ReplyDelete
  27. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.
    Angularjs training in chennai | Angularjs course in Chennai

    ReplyDelete
  28. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Regards,

    PHP Training in Chennai | Webdesigning Training in Chennai

    ReplyDelete
  29. Thanks for sharing this unique and informative content which provided me the required information.
    Java Training in Chennai | JAVA Course in Chennai

    ReplyDelete
  30. Much obliged to you for requiring significant investment to give us a portion of the valuable and restrictive data with us.
    Thanks,
    Hibernate Training in Chennai | Hibernate Training Chennai | Spring and Hibernate Training in Chennai

    ReplyDelete
  31. Thanks for sharing this unique and informative content which provided me the required information.
    Best Angularjs Training in Chennai

    angularjs training center in chennai

    ReplyDelete
  32. Thanks for the share this post with lots of information...
    sap training institute

    ReplyDelete
  33. informative article about Histoire courte. thanks to share.
    hotmail

    ReplyDelete
  34. THanks for sharing.RAP ventures is one of the best inbound marketing agency used to generate more leads through your website with affordable inbound marketing services. Increase the ROI and grow your business.

    ReplyDelete
  35. I would definitely thank the admin of this blog for sharing this information with us. Waiting for more updates from this blog admin.
    Azure Training in Chennai
    Microsoft Azure Training in Chennai
    Azure Training
    Data Science Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  36. Blackjack - Blackjack - JtmHub
    With the most popular and most 태백 출장마사지 popular cards from 용인 출장마사지 casino game dealers worldwide, Blackjack 광명 출장마사지 offers you more than just fun. 전라남도 출장샵 · You'll always find this 경상북도 출장마사지 card

    ReplyDelete
  37. Your weblog is an inordinate measure of impeccable. i've noticed skillfully the thing I was looking. additionally, the substance energies is first rate. gratitude for the bump! Iphone Software Crack

    ReplyDelete
  38. Gambling in South Carolina is restricted solely to on line casino riverboats however state legislature has proposed bills in consecutive years that might open the door to 카지노 사이트 sports activities playing. The state has proposed multiple of} bills, including one in 2021, however all have been shot down. Before they even get to playing, folks must really feel comfy making on-line transactions. Not to fret – in most jurisdictions you can buy purchase|you should buy} Bitcoin directly from Bitstarz with a debit card, GPay, or Revolut. The casino’s accepted withdrawal options embody Interac, eCheck, ecoPayz, and MuchBetter. Moreover, the wagering requirements for the welcome bonus are solely 35x, so you should to} in a position to|be capable of|have the ability to} wrap that up shortly.

    ReplyDelete