You need to sign in to do that
Don't have an account?
Will Jones 18
System.LimitException: Too many future calls: 51 (I believe my code is bulkified)
I am receiving the infamous "System.LimitException: Too many future calls: 51" based on a trigger in my contact object. I am not sure how to handle this as I thought I bulkifie my code and added the statement:
"IF(System.IsBatch() == false && System.isFuture() == false)"
What else could it be?
"IF(System.IsBatch() == false && System.isFuture() == false)"
What else could it be?
trigger PortalContact on Contact (after insert, after update) { //prevents an infinite loop if(Recursion.objectRecursion) return; Recursion.objectRecursion = TRUE; //Create list of contacts List<contact> cont_list = [SELECT Id, Group_Name__c, FirstName, LastName, Email, Portal_Account__c FROM Contact WHERE Id IN: Trigger.newmap.keyset() AND Portal_Account__c = TRUE]; for (Contact c : cont_list) { if(c.Portal_Account__c){ if(!Test.isRunningTest()){ IF(System.IsBatch() == false && System.isFuture() == false){ MySforceHttpCallOut.putDataToRemote_Contact(c.id, c.Group_Name__c, c.FirstName, c.LastName, c.Email); //call a method with @future annotation MySforceHttpCallOut.postDataToRemote_Contact(c.id, c.Group_Name__c, c.FirstName, c.LastName, c.Email); } } } } //process updates if (cont_list.isEmpty()==FALSE){ database.update(cont_list); } }
The reason could be the @future method inside the FOR loop. Try moving outside the FOR loop.
Thanks
Kumar
Your future class method will look like this
1. Get the web service methods you are calling out modified to accept a list of Contacts and process them instead of a single Contact.
Or
2. Since you are making 2 call outs per Contact record, ensure that the batch size is always lesser than or equal to 25. So that you would only use 50 call outs per trigger invocation. All API tools provide a facility to set the batch size as well as you may set the batch size in a batch class written in Apex. Through UI, usually the batch size is 1.
My method that needs adjustment: