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
mukesh gupta 8mukesh gupta 8 

Batch Class Error

Hi Experts,

i wana to update account field value by batch class. But facing a error in attached images.

Please suggest.

User-added image

SandhyaSandhya (Salesforce Developers) 
Hi mukesh Gupta,

please try below code.

In below code account field (this is the field which you want to update)
global class BatchTierUpdate implements Database.Batchable<sObject> {
global final String Query;
global BatchTierUpdate()
Query = 'SELECT Id FROM Account ';

global Database.QueryLocator start(Database.BatchableContext BC) {

    return Database.getQueryLocator(query);

global void execute(Database.BatchableContext BC, List<Account> scope) {


    For (Account ac : scope) {
        ac.accountfeild= 'sandhya';
    update scope;

global void finish(Database.BatchableContext BC) {


Please accept my solution as Best Answer if my answer was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards

Hello Mukhesh,
In order for you to update multiple fields,use it as below .
global final Map<String, String> fieldValues;

global BatchUpdateField(String q, Map<String, String> fieldValues){
Query = q;
this.fieldValues = fieldValues

global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);

global void execute(Database.BatchableContext BC, List<sObject> scope){  
for(sobject s : scope){
for(String fldName : fieldValues.keySet()) {
s.put(fldName, fieldValues.get(fldName));

update scope;

Please mark this as the best answer if you like it.

Rohit Alladi