You need to sign in to do that
Don't have an account?
![sfdeveloper9 sfdeveloper9](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Batch apex start method return
I have a need where I need to check some condition in the start method of a batch apex and based on that database.querylocator query should execute. what is the best way to exit start without running database.queryLocator query. I tried returning null but it throws exception.
The workaround I have for now is putting a limit 0 for the query and executing the database.querylocator like below
if(some condition){
//I want to exit the start method here and continue to the finish method.
return database.queryLocator ('select id from account limit 0');
}
else{
return database.queryLocator ('select id from account');
}
Please let me know if there is any better way to achieve this.
The workaround I have for now is putting a limit 0 for the query and executing the database.querylocator like below
if(some condition){
//I want to exit the start method here and continue to the finish method.
return database.queryLocator ('select id from account limit 0');
}
else{
return database.queryLocator ('select id from account');
}
Please let me know if there is any better way to achieve this.
If you entered in the batch then you can't exit start without running database.queryLocator query.
If you want to this then run batch(Incontroller/ schedular) on condition bases.
If this answers your question then hit Like and mark it as solution!