When updating 115 record through data loader,
i got this error message.
ERROR: UpdateTrigger: System.LimitException: Too many future calls: 51
Originally I thought it was because i was updating more than 50 record.
but I tried it again with 50 record and got the same message.
Plz guys help me out as soon as possible, i will be grateful.
This is my code…
trigger SubscriberUpdateTrigger on Subscriber__c (after Insert, after Update, after delete) {
List<ID> subRecords = new List<ID>();
List<ID> subUpdateRecords = new List<ID>();
Boolean deleteflag = false;
if(!trigger.IsDelete) {
for(Subscriber__c subs : Trigger.new){
if(subs.Active_Subscriber__c == true && subs.Auto_Telemedicine__c == true){
Boolean needsUpdate = false ;
if(Trigger.isInsert){
needsUpdate = true;
}
else if (Trigger.isUpdate){
needsUpdate = false;
}
if(needsUpdate)
subRecords.add(subs.id);
else
subUpdateRecords.add(subs.id);
}
else
{
deleteflag = true;
}
}
if(subRecords.size() >0){
if(system.isFuture())
return;
MDLiveIntegration.insertSubs(subRecords);
}
if(subUpdateRecords.size() >0){
if(system.isFuture())
return;
MDLiveIntegration.updateSubs(subUpdateRecords);
MDLiveIntegration.reactiveSubs(subUpdateRecords);
}
}
else
{
for(Subscriber__c subs : Trigger.old) {
if(subs.Active_Subscriber__c == true && subs.Auto_Telemedicine__c == true){
MDLiveIntegration.deleteSubs(subs.MDLIVE_ID__c,subs.id);
}
}
}
if(deleteflag){
if(Trigger.isUpdate){
for(Subscriber__c subs : Trigger.old) {
MDLiveIntegration.deleteSubs(subs.MDLIVE_ID__c,subs.id);
}
}
}
}
Thanks in advance
Best Answer
The governor limit is that no more than 50 future calls may be made in a single request so your trigger is broken.The governor limit is not about 51 records being called/processed inside a future call, it's about the number of future calls in a single request.
For instance here you are calling future method for each record in Trigger.old based on the if criteria -
Something similar here -
So first alter your future methods to pass the collection of IDs instead of taking a single ID.Then modify your trigger to include eligible records according to your IF condition and then pass it to your future methods to take this list of eligible ids. Also you must be knowing that sObjects can't be passed as arguments.