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.

 

83 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. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.

    SAP training in Chennai

    ReplyDelete

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


    SEO Company in Chennai

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

    ReplyDelete
  40. 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
  41. 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

  42. 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
  43. Thanks for posting this useful content, Good to know about new things here, Let me share this,
    AngularJS Training in Chennai

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

    ReplyDelete
  46. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  47. It is a very nice article including a lot of viral content. I am going to share it on social media. Get the online crackers in chennai.

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

    ReplyDelete
  49. 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
  50. 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
  51. 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
  52. informative article about Histoire courte. thanks to share.
    hotmail

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

    ReplyDelete
  54. 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
  55. 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
  56. 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