2

Getting an error when trying to create this batch class. Could you advise what I'm doing wrong?

Error: Compile Error: Class LocationProcessorBatch must implement the method: void Database.Batchable.execute(Database.BatchableContext, List) at line 1 column 14

global class LocationProcessorBatch implements Database.Batchable<sObject> {

global Integer count = 0;

global Database.QueryLocator start(Database.BatchableContext bc){
    return Database.getQueryLocator('Select Id, Next_Inspection_Date__c FROM SVMXC_Site__c');
}

global void execute(Database.BatchableContext bc, List<SVMXC_Site__c> l_list){        
    List<SVMXC_Site__c> l_list_new = new List<SVMXC_Site__c>();
    for(SVMXC_Site__c l:l_list){
        l.Next_Inspection_Date= Month()+'/15/'+Year();
        l_list_new.add(l);
        count+=1;
    }
    update l_list_new;
}

global void finish(Database.BatchableContext bc){
    System.debug('Count='+count);
   }
}
  • 1
    Please edit to include the complete error text, stack trace (if any), and line location. – David Reed Oct 29 '19 at 17:48
2

Your issue is on this line:

l.Next_Inspection_Date= Month()+'/15/'+Year();

You have missing __c in the field name.

It should be written as one or other as below.

  1. Assuming you are using month() and year() methods from Date class on a date variable:

    Date myDate = date.newInstance(2019, 10, 29);
    l.Next_Inspection_Date__c = myDate.month() + '/15/' + myDate.year();
    

    OR

  2. Assuming you already have a Month(), and Year() methods defined in your class.

    l.Next_Inspection_Date__c = Month() + '/15/' + Year();
    
| improve this answer | |
  • Will myDate.month() get me the current month and myDate.year() get me the current year? – Adam Parker Oct 29 '19 at 18:07
  • It will give you with what you initialized myDate, in the above example it will be 10 and 2019. Depends on what you are trying to achieve. Refer to Date class' documentation for more details – Jayant Das Oct 29 '19 at 18:08
  • Ok, I believe this is what I need: l.Next_Inspection_Date__c= System.Today().Month() +'/15/'+ System.Today().Year(); – Adam Parker Oct 29 '19 at 18:10
  • I'm still getting the original error: Error: Compile Error: Class LocationProcessorBatch must implement the method: void Database.Batchable.execute(Database.BatchableContext, List) at line 1 column 14 – Adam Parker Oct 29 '19 at 18:53
  • If I change the first line to global class LocationProcessorBatch implements Database.Batchable<SVMXC_Site__c> then get the error message Error: Compile Error: Invalid type: SVMXC_Site__c at line 1 column 48 – Adam Parker Oct 29 '19 at 18:57

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.