2

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

2
  • Is MDLiveIntegration.deleteSubs a future method? – Sam Mar 20 '15 at 6:15
  • Yes its a future method.... – Dipen Ishani Mar 20 '15 at 6:24
1

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 -

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);    
            }       
        }

Something similar here -

if(Trigger.isUpdate){
        for(Subscriber__c subs : Trigger.old) {                                                                   
            MDLiveIntegration.deleteSubs(subs.MDLIVE_ID__c,subs.id);             
          }
        }  

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.