You need to sign in to do that
Don't have an account?
Anudeep B
Batch Apex issue.
i am trying to execute below code. where updating a site field in account object.
global class Accbtchstate implements database.batchable<sobject>
{
global database.querylocator start(database.batchablecontext bc)
{
string state = 'select id,name from account';
return database.getquerylocator(state);
}
global void execute(database.batchablecontext bc, list<account> scope)
{
list<account> acc = new list<account>();
for(account a:acc)
{
a.Site = 'No nedd';
acc.add(a);
}
update acc;
}
global void finish(database.batchablecontext bc)
{
}
}
executing using this:
1) Accbtchstate BC = new Accbtchstate();
Database.executeBatch(BC,1000);
please identify problem and guide me how to exactly execute a batch apex.
* i tried all the source to execute.
global class Accbtchstate implements database.batchable<sobject>
{
global database.querylocator start(database.batchablecontext bc)
{
string state = 'select id,name from account';
return database.getquerylocator(state);
}
global void execute(database.batchablecontext bc, list<account> scope)
{
list<account> acc = new list<account>();
for(account a:acc)
{
a.Site = 'No nedd';
acc.add(a);
}
update acc;
}
global void finish(database.batchablecontext bc)
{
}
}
executing using this:
1) Accbtchstate BC = new Accbtchstate();
Database.executeBatch(BC,1000);
please identify problem and guide me how to exactly execute a batch apex.
* i tried all the source to execute.
Scope is an optional parameter for Execute method.
If it is defined and we are passing any number, then the execute method will process that number of records from the list returned by Start method in chunks
If Scope is not defined, then salesforce by default execute in chunks of 200 records at a time.
Scope let us define how many records to be executed at each time from the list returned by Start method. Maximum value of scope is 2000 in batch apex
Regards,
Bhanu Mahesh
All Answers
Hi Anudeep,
You are iterating over a new list which does not have any elements.
You have to iterate over scope
Add Site field in query
The class will be as below
executing this in Developer console:
Accbtchstate BC = new Accbtchstate();
Database.executeBatch(BC,1000);
Regards,
Bhanu Mahesh
i have a doubt we doing operation on Account object, why do we go to scope.
Actually what is the purpose of "scope" in batch apex, i tied to know that but it not get any claryfication for me please help me on this..
Thanks.
Scope is an optional parameter for Execute method.
If it is defined and we are passing any number, then the execute method will process that number of records from the list returned by Start method in chunks
If Scope is not defined, then salesforce by default execute in chunks of 200 records at a time.
Scope let us define how many records to be executed at each time from the list returned by Start method. Maximum value of scope is 2000 in batch apex
Regards,
Bhanu Mahesh