You need to sign in to do that
Don't have an account?
swathi medak 9
calling class from execute fuction in batchclass
Hi,
plz tell me whats wrong with my code:
global class batchaccountdescupdate implements database.batchable<sObject>,database.stateful{
global Database.QueryLocator start(Database.BatchableContext BC){
string query='SELECT Description FROM Account';
return Database.getQueryLocator(query);
}
global void execute(database.batchablecontext BC, list<Account> scope){
for(Account a: scope){
if(a.Description=='Not Available')
a.Description='Please fill details, else record will be made inactive';
}
update scope;
}
global void finish(database.batchablecontext BC,list<Account> scope){
integer totalemployeecount=0;
for(Account a: scope){
totalemployeecount=totalemployeecount+a.NumberOfEmployees;
}
update scope;
}
}
here is the error im getting:
Error: Compile Error: Class batchaccountdescupdate must implement the method: void Database.Batchable<SObject>.finish(Database.BatchableContext) at line 1 column 14
thanks.
plz tell me whats wrong with my code:
global class batchaccountdescupdate implements database.batchable<sObject>,database.stateful{
global Database.QueryLocator start(Database.BatchableContext BC){
string query='SELECT Description FROM Account';
return Database.getQueryLocator(query);
}
global void execute(database.batchablecontext BC, list<Account> scope){
for(Account a: scope){
if(a.Description=='Not Available')
a.Description='Please fill details, else record will be made inactive';
}
update scope;
}
global void finish(database.batchablecontext BC,list<Account> scope){
integer totalemployeecount=0;
for(Account a: scope){
totalemployeecount=totalemployeecount+a.NumberOfEmployees;
}
update scope;
}
}
here is the error im getting:
Error: Compile Error: Class batchaccountdescupdate must implement the method: void Database.Batchable<SObject>.finish(Database.BatchableContext) at line 1 column 14
thanks.
Move your code logic from the finish method to the execute method. Start and finish methods just run once. So, any logic that involves iterating over a list of records should be put in the execute method. Also, if you are using NumberOfEmployees field, you need to add the same in the query of the start method.
Use Batch Apex (https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_batch)
You can try something like this:
All Answers
Move your code logic from the finish method to the execute method. Start and finish methods just run once. So, any logic that involves iterating over a list of records should be put in the execute method. Also, if you are using NumberOfEmployees field, you need to add the same in the query of the start method.
Use Batch Apex (https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_batch)
You can try something like this:
You can try this.
global class batchaccountdescupdate implements Database.Batchable<sObject>,database.stateful{
global Database.QueryLocator start(Database.BatchableContext BC){
string query='SELECT Description FROM Account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, list<Account> scope){
for(Account a: scope){
if(a.Description=='Not Available')
a.Description='Please fill details, else record will be made inactive';
}
update scope;
}
global void finish(Database.BatchableContext BC){
}
}
Note- If you want to do this operation then write this code inside the execute method.
integer totalemployeecount=0;
for(Account a: scope){
totalemployeecount=totalemployeecount+a.NumberOfEmployees;
}
update scope;
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Greetings to you
I have implemented your code and the error is showing because you have written a second parameter list<Account> scope in finish method.
You cannot give a second parameter in finish method because finish method is a single parameterised metrhod.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha