0

I have This Code -->

global class ExpiryDateBatchCls implements Database.Batchable<sObject>{
     global final DateTime  startDate;
     global final DateTime  EndDate;

   global ExpiryDateBatchCls(dateTime sd,dateTime ed){
       StartDate=sd;
       EndDate=ed;
   }

    global Database.querylocator start(Database.BatchableContext BC){
       List<IP__Renewal__c> renewals = new List<IP__Renewal__c>([SELECT Id FROM IP__Renewal__c WHERE IP__IP_Right__r.IP__AppDate__c!=null and IP__IP_Right__r.Split_Entity__c='BIIB' and IP__IP_Right__r.Annuity_Responsible__c='YES' and  IP__IP_Right__r.Annuity_Eligible__c ='YES' and IP__IP_Right__r.IP__IPR_Type__c in ('Patent','Design','Utility Model','Defensive Publication') and
            IP__Due_Date__c >=: startDate AND IP__Due_Date__c <=:endDate]);
       return Database.getQueryLocator(renewals);
    }

    global void execute(Database.BatchableContext bc ){
      // renewals = bc.

        for(IP__Renewal__c renewal : renewals){
            System.debug(renewal.Id);
            Database.executeBatch(new BatchQuotesRequest(startDate, renewal.Id));
        }
     }      

    global void finish(Database.BatchableContext bc){
    }    
}

This show Error

Variable does not exist: renewals

1

3 Answers 3

1

Change execute method to the following:

global void execute(Database.BatchableContext bc, List<IP__Renewal__c> renewals )
}
1

I think you have missed list< IP__Renewal__c > scope and reffred renewals instead of scope

global ExpiryDateBatchCls(dateTime sd,dateTime ed){ StartDate=sd; EndDate=ed; }

global Database.querylocator start(Database.BatchableContext BC){
   List<IP__Renewal__c> renewals = new List<IP__Renewal__c>([SELECT Id FROM IP__Renewal__c WHERE IP__IP_Right__r.IP__AppDate__c!=null and IP__IP_Right__r.Split_Entity__c='BIIB' and IP__IP_Right__r.Annuity_Responsible__c='YES' and  IP__IP_Right__r.Annuity_Eligible__c ='YES' and IP__IP_Right__r.IP__IPR_Type__c in ('Patent','Design','Utility Model','Defensive Publication') and
        IP__Due_Date__c >=: startDate AND IP__Due_Date__c <=:endDate]);
   return Database.getQueryLocator(renewals);
}

global void execute(Database.BatchableContext bc ,list<IP__Renewal__c> scope){
  // renewals = bc.

    for(IP__Renewal__c renewal : scope){
        System.debug(renewal.Id);
        Database.executeBatch(new BatchQuotesRequest(startDate, renewal.Id));
    }
 }      

global void finish(Database.BatchableContext bc){
}    
}
1

You need to modify the batch class as per the example in documentation:

global class ExpiryDateBatchCls implements Database.Batchable<sObject>{
     global final DateTime  startDate;
     global final DateTime  EndDate;

   global ExpiryDateBatchCls(dateTime sd,dateTime ed){
       StartDate=sd;
       EndDate=ed;
   }

    global Database.querylocator start(Database.BatchableContext BC){
       return Database.getQueryLocator('SELECT Id FROM IP__Renewal__c WHERE IP__IP_Right__r.IP__AppDate__c!=null and IP__IP_Right__r.Split_Entity__c='BIIB' and IP__IP_Right__r.Annuity_Responsible__c='YES' and  IP__IP_Right__r.Annuity_Eligible__c ='YES' and IP__IP_Right__r.IP__IPR_Type__c in ('Patent','Design','Utility Model','Defensive Publication') and
            IP__Due_Date__c >=: startDate AND IP__Due_Date__c <=:endDate');
    }

    global void execute(Database.BatchableContext bc, List<sObject> scope){
      renewals = (IP__Renewal__c) scope;

      for(IP__Renewal__c renewal : renewals){
          System.debug(renewal.Id);
          Database.executeBatch(new BatchQuotesRequest(startDate, renewal.Id));
      }
    }      

    global void finish(Database.BatchableContext bc){
    }    
}

Note: Avoid querying inside a start method, instead pass SOQL to querylocator, otherwise batch will try to query all data in start method. This defeats the purpose of using a batch class which is for handling large data in chunk of records.

2
  • line breaks not allowed in string literals in 11 line
    – Atul
    Jun 6, 2017 at 11:35
  • your query should be in single line. Here the query string is in 2 lines.
    – Raul
    Jun 6, 2017 at 11:41

You must log in to answer this question.

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