1
global class batchorgUpdate implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id,Name, Appraisal__c,Designation__c,Employee_Name__c,Grade__c,  Salary_Scale__c FROM Organization__c';
        return Database.getQueryLocator(query);
    }  
    global void execute(Database.BatchableContext BC, List<Organization__c> org) {
             for(Organization__c r : org)
          {
               if(r.Salary_Scale__c==10000)
              {
                     r.Grade__c='C';
                     r.Designation__c='JD';
              }
               if(r.Appraisal__c==10 &&  r.Designation__c=='JD' && r.Salary_Scale__c==10000)
              {
                      r.Grade__c='C+';
                      r.Salary_Scale__c=11000;
              }    
               if(r.Appraisal__c==10 &&  r.Designation__c=='JD' && r.Salary_Scale__c==11000)
              {
                      r.Grade__c='B';
                      r.Salary_Scale__c=12000;
              }    
                if(r.Salary_Scale__c==20000)
              {
                      r.Grade__c='A';
                      r.Designation__c='SD';
                      r.Appraisal__c=null;
              }        
          }
         update org;
    } 
    global void finish(Database.BatchableContext BC) {
    }
}
0

In your test insert a small number of Organization__c objects with field values that match the various cases in your code.

Then run your Batchable ensuring that the execute method is only called once (a limitation in tests) by specifing a batch size that is greater than the number of Organization__c objects you inserted:

Test.startTest();
Database.executeBatch(new batchorgUpdate(), 200);
Test.stopTest();

The Test.stopTest documentation explains that:

All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously.

Then re-query the Organization__c objects and assert that the expected changes have been made.

0

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.