I'm getting an error 'Argument must be an inline query' on the return line. Does that mean I need to make a query of my sObject in the parameter of the getQueryLocator() as opposed to passing in a variable for a List of opportunities?
public Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(woList);
}
where List<Opportunity> woList = new List<Opportunity>(trigger.new);
I would use my query there, but I'm writing a batchable class for a before Insert trigger. I can't think of anyway to write the query to identify the opportunities in trigger.new
as they don't have Ids assigned yet.
Within context, I am trying to lookup a value passed in on an Opportunity (fs_wmCompanyId__c). I will then need to look to the account table to see if any account has that same value stored in a field (fs_wmCompanyId__c) on that table; if there is I will need the account ID. I will then loop back to the inserted Opportunity and set the account Id in the rs_client__c field.
I have it on a before insert trigger to ensure the rs_client__c field is set prior to saving the record; this was to make sure no validation rules prevent the update after save and that no integrations with other systems sync the data without the rs_client__c field. I figured the trigger should call a batchable class in case several hundred records were inserted at once. This is my first piece of code, so feel free to rip it apart and critique.
iterable
but let's not touch it). So if anything - it should probably be in "after insert". It's quite dangerous to fire batches off a trigger, you might hit the limit of max 5 jobs running at same time. And batch won't be tied to the trigger (it won't be "before" anymore when it finishes the calculation). Can you tell us what's the end result you're trying to achieve? Maybe you'd be better off with@future
or scheduled batch running for example every hour?