0

Description I am getting huge 30 mb csv data in chunks via api from aws and passing these chunks in Queueable Class that is called from same api class. Queueable Class is further calling batch apex with batch size 1. DML operation is after callout but i am stuck.

END

Queueable Apex

public ESGGetCompanyAnalyticsServiceAWSQueable(list<ESGGetCompanyAnalyticsServiceAWS.ESGCompanyFieldsWrapper> recs) {
      this.ESGCompanyFieldsWrapperLst=recs;
      recs= new list<ESGGetCompanyAnalyticsServiceAWS.ESGCompanyFieldsWrapper>(); 
      system.debug('proco__ESG_Company__c DataQ>>>>>>' + this.ESGCompanyFieldsWrapperLst);
  }
  
  public  void execute(QueueableContext queCont) {
        list<ESGGetCompanyAnalyticsServiceAWS.ESGCompanyFieldsWrapper> ESGCompanyFieldsWrapperLst1=this.ESGCompanyFieldsWrapperLst;
      if(this.ESGCompanyFieldsWrapperLst !=Null)
      {
    system.debug('>>>>>>>>>>>>>>>>>'+this.ESGCompanyFieldsWrapperLst);
    this.ESGCompanyFieldsWrapperLst= new list<ESGGetCompanyAnalyticsServiceAWS.ESGCompanyFieldsWrapper>();
      ESGGetCompanyAnalyticsServiceAWSBatch zib = new ESGGetCompanyAnalyticsServiceAWSBatch(this.ESGCompanyFieldsWrapperLst); 
      Id jobId= database.executeBatch(zib,10);
      
      ESGCompanyFieldsWrapperLst1= new list<ESGGetCompanyAnalyticsServiceAWS.ESGCompanyFieldsWrapper>();
    this.ESGCompanyFieldsWrapperLst= new list<ESGGetCompanyAnalyticsServiceAWS.ESGCompanyFieldsWrapper>();
}

END

METHOD Calling API AND QUEUEABLE CLASS

public static String saveFile() {
            //csv=null;
            Http http = new Http();
            HttpRequest req= createHttpRequest();
            HttpResponse response = http.send(req);
            String responseBody= response.getBody();
            list<String> columnValues = new list<String>();
            list<String> filelines =responseBody.split('\n');
            system.debug('Debug filelinesESGCompanyFieldsWrapperLstESGCompanyFieldsWrapperLst>>>  filelines.add(string.valueOf(r)'+filelines);
            transient list<ESGCompanyFieldsWrapper> ESGCompanyFieldsWrapperLst= new list<ESGCompanyFieldsWrapper>();            
            system.debug('Debug filelinesESGCompanyFieldsWrapperLstESGCompanyFieldsWrapperLst>>>');
            if(filelines.size()>0)
            {

            for (Integer j=0;j<filelines.size();j++)
            {
                system.debug('insidefor>>');
            columnValues = filelines[j].split(',');
            ESGCompanyFieldsWrapper esg= new ESGCompanyFieldsWrapper();
            esg.ESG_Company_Id = columnValues[0];
            esg.Prospect_Company_Name = columnValues[1];
            esg.Air_Quality_avg = columnValues[2];
            esg.Access_and_Affordability ='0';// columnValues[3];
            esg.Access_and_Affordability_avg ='0';// columnValues[4];
            esg.Air_Quality = columnValues[5];
            esg.Business_Ethics = columnValues[6];
            esg.Business_Ethics_avg = columnValues[7];
            esg.Business_Model_Resilience = columnValues[8];
            esg.Business_Model_Resilience_avg = columnValues[9];
            esg.Competitive_Behavior = columnValues[10];
            esg.Competitive_Behavior_avg = columnValues[11];
            esg.Critical_Incident_Risk_Management = columnValues[12];
            esg.Critical_Incident_Risk_Management_avg = columnValues[13];
            esg.Customer_Privacy = columnValues[14];
            esg.Customer_Privacy_avg = columnValues[15];
            esg.Customer_Welfare = columnValues[16];
            esg.Customer_Welfare_avg =0;//columnValues[17];
            esg.Data_Security = 0;//columnValues[18];//columnValues[18];
            esg.Data_Security_avg =0;// columnValues[19];
            esg.Ecological_Impacts = 0;//columnValues[20];
            esg.Ecological_Impacts_avg = 0;//columnValues[21];
            esg.Employee_Engagement_Diversity_AND_In_avg =0;// columnValues[22];
            esg.Employee_Engagement_Diversity_And_Incl =0;// columnValues[23];
            esg.Employee_Health_And_Safety = 0;//columnValues[24];
            esg.Employee_Health_And_Safety_avg =0;// columnValues[25];
            ESGCompanyFieldsWrapperLst.add(esg);
                 
            }
                }
               system.debug('Debug outside for ESGCompanyFieldsWrapperLst>>'+ESGCompanyFieldsWrapperLst.size());
               
               ID jobID =  System.enqueuejob(new ESGGetCompanyAnalyticsServiceAWSQueable(ESGCompanyFieldsWrapperLst));

               filelines=new List<string>();
               ESGCompanyFieldsWrapperLst= new List<ESGCompanyFieldsWrapper>();
    return 'success';
}

END

8
  • Can you paste the full code, I dont see any DML in above code Commented Nov 29, 2022 at 7:15
  • DML is in batch that is being called from queueable class
    – rose
    Commented Nov 29, 2022 at 7:37
  • 1
    And where is callout happening? Commented Nov 29, 2022 at 7:43
  • First Code is for callout as you can see
    – rose
    Commented Nov 29, 2022 at 7:50
  • 1
    Please share the full code from where the api is being fired and how that is connected to Queueable and Batch class. Commented Nov 29, 2022 at 7:59

1 Answer 1

0

By viewing your code it is not possible to face the error System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

Here are two scenarios where this exception comes and check what is actually happening.

  1. Calling a Queueable or future before callout. (This also gets considered as DML before callout)

  2. Doing a DML (insert, update, upsert, delete) before callout.

Please check if either of these combinations are in your code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .