You need to sign in to do that
Don't have an account?
Batching Submit For Approval From Triggers
Hello,
I wrote a generic trigger that submits an Opportunity for approval when a picklist meets the appropriate criteria. The purpose is to allow us to submit using a workflow rule/upload etc.
Code is here:
trigger SubmitFromTrigger on Opportunity (after insert, after update) {
list<Opportunity> updateOpps = new list<Opportunity>();
for(Opportunity opp : trigger.new){
if( opp.submit_from_trigger__c == 'Yes'){
Opportunity placeHolderOpp = new Opportunity(id = opp.id, submit_from_trigger__c = 'No');
updateOpps.add(placeHolderOpp);
approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setObjectId(opp.id);
approval.ProcessResult result = Approval.process(req1);
}
}
Update updateOpps;
}
This script works as it is supposed to. The only problem is that I could not figure out how to batch the submit for approval command, so when I ran a test in our sandbox submitting 23 at a time it worked, but when I did it using 102 it did not.
So I guess my questions are 1) Is it possible to batch the approval submit command, 2) If so, how?, and 3) If not, can we change that in an upcoming release?
Thanks,
Geoffrey
Thanks for the tip. Looks like all I had to do was add "[]" to the end of the result call. Final code is here:
trigger SubmitFromTrigger on Opportunity (after insert, after update) {
list<Opportunity> updateOpps = new list<Opportunity>();
list<Approval.ProcessSubmitRequest> reqList = new list<Approval.ProcessSubmitRequest>();
for(Opportunity opp : trigger.new){
if( opp.submit_from_trigger__c == 'Yes'){
Opportunity placeHolderOpp = new Opportunity(id = opp.id, submit_from_trigger__c = 'No');
updateOpps.add(placeHolderOpp);
approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setObjectId(opp.id);
reqList.add(req1);
}
}
approval.ProcessResult[] result = Approval.process(reqList);
Update updateOpps;
}
All Answers
Thanks for the tip. Looks like all I had to do was add "[]" to the end of the result call. Final code is here:
trigger SubmitFromTrigger on Opportunity (after insert, after update) {
list<Opportunity> updateOpps = new list<Opportunity>();
list<Approval.ProcessSubmitRequest> reqList = new list<Approval.ProcessSubmitRequest>();
for(Opportunity opp : trigger.new){
if( opp.submit_from_trigger__c == 'Yes'){
Opportunity placeHolderOpp = new Opportunity(id = opp.id, submit_from_trigger__c = 'No');
updateOpps.add(placeHolderOpp);
approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setObjectId(opp.id);
reqList.add(req1);
}
}
approval.ProcessResult[] result = Approval.process(reqList);
Update updateOpps;
}