0

My trigger

trigger triggSendRebateData on RebateData_for_MC__c (before insert,before update) {
   List<RebateData_for_MC__c> lstRebateData = new List<RebateData_for_MC__c>();

   for(Integer i=0;i<Trigger.new.size();i++){
    system.debug('iiii'+i +Trigger.new.size());
          lstRebateData.add(Trigger.new[i]);      
  }

  if(!lstRebateData.isEmpty()){
      ID jobID = System.enqueueJob(new RebateDataQueue(lstRebateData));
  }
}

My Class

public class RebateDataQueue implements Queueable, Database.AllowsCallouts {

    private List<RebateData_for_MC__c> lstRebate;

    public RebateDataQueue(List<RebateData_for_MC__c> lstRb){
        this.lstRebate = lstRb;
    }

    public void execute(QueueableContext context) {
        if(!lstRebate.isEmpty()){
        for(RebateData_for_MC__c rbData:lstRebate){
TriggeredSendEmail.postMailtoET(rbData.name,rbData.address__c,rbData.BusinessUnit__c,rbData.ERp__c,rbData.ABN__c);
}
}
}

TriggeredSendEmail Class

public class TriggeredSendEmail{ 
 @future(callout=true)
      public static void postMailtoET(string name,string addressLine1,string businessunit,string erp,string abn){
//some code here
}
}

I'm trying to insert around 250 records by calling the method in developer console and this is the error i'm getting. How to overcome this

enter image description here

Eagerin Sf
  • 1,085
  • 5
  • 36
  • 72
  • don't have postMailtoET in a for loop. Also you can check that you have enough of a limit remaining before doing the call. – Aequitas Feb 13 '18 at 04:40
  • Instead of passing individual records of "RebateData_for_MC__c" to future method, you can pass entire list of RebateData_for_MC__c. And in future method you can do your processing. So that you are just making 1 future call. – user36778 Feb 13 '18 at 04:54
  • @user36778 How can I pass list of RebateData Records. Sample Example please – Eagerin Sf Feb 13 '18 at 06:50
  • Why postMailtoET is a future function,? You call it in a queue tha means it is already a future context. – Simonp Feb 13 '18 at 06:58

0 Answers0