I want to retrieve Leads
and Accounts
in Apex start
function and update the owner field
How can that be achieved?
global Database.QueryLocator start(Database.BatchableContext BC) {
//query leads and accounts
}
global void execute(Database.BatchableContext BC, List<sObject> object) {
//update leads and accounts
}
global void finish(Database.BatchableContext BC) {
}
Edit
I have a custom object that has a field that contains a user Id. If this field is updated from user A Id to user B Id for example, a trigger calls the batch method. Leads and Accounts where the owner is A need to be retrieved and then the owner field should be updated by the new value which is user Id B.
QueryLocator
. You could do it by returningList<SObject> start
instead, but that would be more limited in volume. Curious to know a little bit more about your requirements. Recommended approach could vary based on the scenario. What conditions lead records into this batch in the first place?