function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohidheen NMohidheen N 

Apex batch class in batches issue

Hi ,

Can any one help me with the below .

I try to update all te account description with value "Testing 2" in my batches. I tried to update account description by picking 10 10 Acounts, But its updating only first 10 set of records and skipping remainign records.

Can you pls guide me where am wrong.

public class first_batch2_withuser_query implements Database.Batchable<sObject>{

  public final  String Field;
  public final  String Query;
  public final  String Value;
        public first_batch2_withuser_query (String f, String q, String v){
    Field =f;    Query =q;   Value =v;
    }
     public Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(Query);
    }
       public void execute(Database.BatchableContext BC, List<Account> Scope){
    for (Account a: Scope){
    a.put(Field,Value);
        }
    update Scope;    
    }
public void finish(Database.BatchableContext BC){
}
}

I tried with below methods but not updating all the accounts in batches.

String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID batchinstanceID= Database.executeBatch(new first_batch2_withuser_query(f,q,v),5);

​String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID batchinstanceID= Database.executeBatch(new first_batch2_withuser_query(f,q,v));

String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID jobID= Database.executeBatch(new first_batch2_withuser_query(f,q,v));
Best Answer chosen by Mohidheen N
Ishwar ShindeIshwar Shinde
Update your string var q as -
String q= 'Select Description from Account';

and execute the batch.

All Answers

Raj VakatiRaj Vakati
Your code is working ..  Please Limit limit 10 in the query so that you can able to see the all account description is updated and its easy for testing ..  

 
Ishwar ShindeIshwar Shinde
Update your string var q as -
String q= 'Select Description from Account';

and execute the batch.
This was selected as the best answer
Mohidheen NMohidheen N
Hi Raj V and Ishwar , Many thanks , Issue resolved i able to perform my testing batches succesfully as per my required batches.