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.

 

99 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
    Replies
    1. Thanks for writing in such an encouraging post. I had a glimpse of it and couldn’t stop reading till I finished. I have already bookmarked you. hotel management colleges in punjab

      Delete
    2. I feel this is among the such a lot vital info for me. And i am satisfied studying your article. However wanna commentary on few general things, The website style is ideal, the articles is truly nice
      Tangki Panel
      Tangki Fiberglass
      Jual Septic Tank

      Delete
  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
    Replies
    1. Hibernate Training Institutes in ChennaiHibernate Training Institutes in Chennai Hibernate Online Training Hibernate Online Training Hibernate Training in Chennai Hibernate Training in Chennai Java Online Training Java Online Training

      Delete
    2. Hey, nice site you have here! Keep up the excellent work! web designing in jalandhar

      Delete
  3. In near future, big data handling and processing is going to the future of IT industry. Thus taking Hadoop Training in Chennai | Big Data Training in Chennai will prove beneficial for talented professionals.

    ReplyDelete
    Replies
    1. An important building block of SEO is to develop your website which can be easily understandable for both Online Visitors (most important) and search engine robots. In the current digital age, seo is important for your online success means to generate leads.

      SEO Services in IndiaSEO Company in India SEO Company in India SEO Services in India

      SEO Company in India SEO Services in India

      Delete
  4. 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
  5. This technical post helps me to improve my skills set, thanks for this wonder article I expect your upcoming blog, so keep sharing.
    Regards,
    ccna course in Chennai|ccna training in Chennai|ccna training institute in Chennai|ccna institutes in Chennai

    ReplyDelete
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. As the world is constantly getting advanced digitally for every brand or a company it is very improtant to mark their presence online. not only to mark their presence they also have to be very active on the web so that they can have a conversation with their clients/customers and solve their problems or improve their service.
    Digital Marketing Training in Chennai|Digital Marketing Course in Chennai|Digital Marketing Chennai

    ReplyDelete
  12. Hi Admin, I went through your article and it’s totally awesome. You can consider including RSS feed for easy content sharing, So that you can drive huge traffic to your blog. Hadoop Training in Chennai | Big Data Training in Chennai

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

    Android Application Development

    ReplyDelete
  14. 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
  15. 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
  16. This comment has been removed by the author.

    ReplyDelete
  17. 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
  18. 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
  19. 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
  20. Awesome..You have clearly explained ...Its very useful for me to know about new things..Keep on blogging..
    Java Training in Chennai

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

    ReplyDelete
  22. 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
  23. 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


  24. 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
  25. 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
  26. 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

  27. 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

  28. 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
  29. 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
  30. Great and useful article. Creating content regularly is very tough. Your points are motivated me to move on.


    SEO Company in Chennai

    ReplyDelete
  31. Great and useful article. Creating content regularly is very tough. Your points are motivated me to move on.


    SEO Company in Chennai

    ReplyDelete
  32. Thanks for sharing this informative content that guided me to know the details about the training offered in different technology.
    digital marketing course in chennai | digital marketing training in Chennai

    ReplyDelete
  33. I have read your blog its very attractive and impressive. I like it your blog.


    JavaEE Training in Chennai JavaEE Training in Chennai

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Java 8 Training in Chennai

    ReplyDelete
  34. 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
  35. 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
  36. 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
  37. 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
  38. Thanks for sharing this unique and informative content which provided me the required information.
    Java Training in Chennai | JAVA Course in Chennai

    ReplyDelete
  39. 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
  40. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Dot net training in Chennai | dot net course in Chennai

    ReplyDelete

  41. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
    Regards,'
    Performance Tuning Training in Chennai | Oracle PL/SQL Training in Chennai

    ReplyDelete
  42. 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
  43. All collective information are really useful you have good matter about this topic, Thank u so much. medical tourism in india

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

    ReplyDelete
  45. Good post and I like it very much. By the way, anybody try this app development company for iOS and Android? I find it is so professional to help me boost app ranking and increase app downloads.

    ReplyDelete
  46. I like the post format as you create user engagement in the complete article. It seems round up of all published posts. Thanks for gauging the informative posts.
    cara menggugurkan kandungan

    ReplyDelete
  47. a pride for me to be able to discuss on a quality website because I just learned to make an article on
    cara menggugurkan kandungan

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

    ReplyDelete
  49. Do you consider excitement your second name? Then you to us. funny online gambling games Online games for you.

    ReplyDelete
  50. 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
  51. 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
  52. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way. T hank you so much.



    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery








    ReplyDelete
  53. 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
  54. Incredible post I should say and a debt of gratitude is in order for the data. Schooling is certainly a tacky subject. Be that as it may, is still among the main subjects within recent memory. I appreciate your post and anticipate more. You have made some valid statements there. I looked on the web to study the issue and discovered a great many people will oblige your perspectives on this site...
    how to make a paper airplane eagle | how to make a boomerang airplane | the eagle paper airplane | best paper airplane design for distance and accuracy | best paper airplanes for distance and speed | what is the best paper airplane design for distance | paper airplane that flies far and straight | nakamura lock paper airplane instructions | paper airplane templates for distance | science behind paper airplanes

    ReplyDelete
  55. İnstagram takipçi satın al! İnstagram takipçi sitesi ile takipçi satın al sende sosyal medyada fenomen olmaya bir adım at. Sende hemen instagram takipçi satın almak istiyorsan tıkla:

    1- takipçi satın al

    2- takipçi satın al

    3- takipçi satın al

    ReplyDelete
  56. 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
  57. Yet again yet again a couple of times, you can defer and restart exercises; the result results can be protected and imported, similarly as at whatever point you restart, there is compelling reason need to check. Easeus Data Recovery Wizard License Code

    ReplyDelete
  58. I have Been addressing pretty much this count number, as a final product gratitude for posting. cold publication.It 's as a matter of fact exceptionally fine and helpful say.thank you Happy Birthday Famous Quotes

    ReplyDelete
  59. 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