You need to sign in to do that
Don't have an account?
A Raj 9
Hi All, I wrote this Batch code, and is not showing any error and also it is running anonymously, but record is not getting updated
Hi All, I wrote this Batch code, and is not showing any error and also it is running anonymously, but record is not getting updated
public class fieldupdate1 implements Database.Batchable<SObject>{
public Database.querylocator start(Database.BatchableContext bc){
string query = 'select id, name, industry from account';
return database.getquerylocator(query);
}
public void execute(Database.BatchableContext bc, list<Account> scope){
list<Account> accs = new list<account>();
for(Account a : scope){
for(integer i=25;i<30;i++){
if(a.name == 'Test Batch'+i){a.industry='Agriculture';}
accs.add(a);
}
}
update accs;
}
public void finish(Database.BatchableContext bc){}
}
public class fieldupdate1 implements Database.Batchable<SObject>{
public Database.querylocator start(Database.BatchableContext bc){
string query = 'select id, name, industry from account';
return database.getquerylocator(query);
}
public void execute(Database.BatchableContext bc, list<Account> scope){
list<Account> accs = new list<account>();
for(Account a : scope){
for(integer i=25;i<30;i++){
if(a.name == 'Test Batch'+i){a.industry='Agriculture';}
accs.add(a);
}
}
update accs;
}
public void finish(Database.BatchableContext bc){}
}
Did you check in debug what does the following variables contain:
1. scope
2. accs
Cheers!!!!
As per your code if Account name is 'Test Batch'25(OR 26 OR 27 OR 28 OR 29) then you are updating Industry to 'Agriculture'
Please try below code:
public class fieldupdate1 implements Database.Batchable<SObject>{
public Database.querylocator start(Database.BatchableContext bc){
string query = 'select id, name, industry from account';
return database.getquerylocator(query);
}
public void execute(Database.BatchableContext bc, list<Account> scope){
list<Account> accs = new list<account>();
for(Account a : scope){
for(integer i=25;i<30;i++){
if(a.name == 'Test Batch'+i){a.industry='Agriculture';
accs.add(a);
}
}
}
update accs;
}
public void finish(Database.BatchableContext bc){}
}
like below
***************************
for(Account a : scope){
for(integer i=25;i<30;i++){
if(a.name == 'Test Batch'+i){a.industry='Agriculture';
}
}
accs.add(a);
}
*************************
Thank you.
Thanks