You need to sign in to do that
Don't have an account?
srikanth cheera 6
please check the code and write test class
global class Task020 implements database.Batchable<sobject>{
global database.QueryLocator start(database.BatchableContext bc){
return database.getQueryLocator('select id,name from Account where createddate= Today()');
}
global void execute(database.BatchableContext bc,list<Account> acc){
for(Account a:acc){
}
delete acc;
}
global void finish(database.BatchableContext bc){
}
}
global database.QueryLocator start(database.BatchableContext bc){
return database.getQueryLocator('select id,name from Account where createddate= Today()');
}
global void execute(database.BatchableContext bc,list<Account> acc){
for(Account a:acc){
}
delete acc;
}
global void finish(database.BatchableContext bc){
}
}
Please try once below code :
Thanks
Varaprasad
Please check once below code :
Hope this helps you.
Thanks
varaprasad
Please change your batch apex class like above your class is having an issue with the query like today.
Please add above batch class first and then run your test class.
Thanks
Varaprasad
Please do the below changes in your Batch job first
1) Change the query from select id,name from Account where createddate= Today()
to
select id,name from Account where createddate = Today
Please check below post for date filter in query
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
2) No need to below code as you are delete all record in your batch job
for(Account a:acc){
}
You Batch job should be like below
I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
3) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Test Class for Batch job
1) http://amitsalesforce.blogspot.com/search/label/Batch%20Job
Sample test class to start NOTE:- Always add Assert in Test class to validate the result
i tested the same code and working fine in my dev org
Let me know if this will help you