You need to sign in to do that
Don't have an account?

Error in Batch Apex
when i written the below program using batch apex topic its getting error in line 1 and 6
global class Batch_Example implements Database.Batchable<sobject>{
global Database.QueryLocator start(Database.BatchableContext bc){
String query='Select id,name.stagename,CloseDate from opportunity Where Createddate=THIS_MONTH';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<opportunity> optList){
for(opportunity op:optList)
{
op.StageName='closed Won';
op.Closedate=system.today();
}
update optList;
}
global void finish(Database.BatchableContext bc){
}
}
error message -1.Class Batch_Example must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)
2.global methods do not support parameter type of List<Opportunity>
global class Batch_Example implements Database.Batchable<sobject>{
global Database.QueryLocator start(Database.BatchableContext bc){
String query='Select id,name.stagename,CloseDate from opportunity Where Createddate=THIS_MONTH';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<opportunity> optList){
for(opportunity op:optList)
{
op.StageName='closed Won';
op.Closedate=system.today();
}
update optList;
}
global void finish(Database.BatchableContext bc){
}
}
error message -1.Class Batch_Example must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)
2.global methods do not support parameter type of List<Opportunity>
The problem is the implementation of execute method. It has wrong parameters. Check out this code:
Regards.
I tried the same code but I make only make a change in the query and it works fine.
String query='Select id,name,stagename,CloseDate from opportunity WHERE CreatedDate = THIS_MONTH';
In your code in your query you have written "name.stagename" that is incorrect.
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
Which API version are you using?
I used API 41.0 and worked without any errors.
Regards.