2

I just created a batch that set some null values in some fields, what I notice is that the batch sets the nulls but it does not update the Object. I need to Edit and Save in order to see the new values. Any ideas? Thank you!

here is the batch code:

  global class batchTaxValues implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
    String query = 'SELECT State_Tax_Rate__c, City__c, Special_Tax_Rate__c,County_Tax_Rate__c FROM MWSOrderItem__c';
    return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<MWSOrderItem__c> scope)
{
     for(MWSOrderItem__c a : scope)
     {
         a.State_Tax_Rate__c = null ; 
         a.City__c = null;
         a.Special_Tax_Rate__c = null;
         a.County_Tax_Rate__c = null;         
     }
     update scope;
}  
global void finish(Database.BatchableContext BC)
{
}

}

here is the Scheduler class:

global class BatchSchedulerTaxValues implements Schedulable {
global void execute(SchedulableContext sc){
     database.executeBatch(new batchTaxValues());

}

}

  • 2
    What do you mean you need to edit and save to see the new values? Were you on a record when the batch ran? Did you refresh the page? When you clicked edit was the fields on the edit page null? How long after the batch ran did you check the results in the record? Just a bit confused. – Eric Apr 25 '14 at 23:07
  • Hi Eric, I have only one record in the object. I I refreshed the record and nothing, I had the record open while testing. Do you see anything wrong in the batch? – Carlos Apr 25 '14 at 23:13
  • Never mind, it is working I just need to wait more time. Thank you ! – Carlos Apr 25 '14 at 23:27
  • Thats what I thought it may be... – Eric Apr 25 '14 at 23:41

Your Answer

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

Browse other questions tagged or ask your own question.