You need to sign in to do that
Don't have an account?
HuluSFAdmin
Triggering Approval processes from APEX code
Hello,
I am trying to programatically trigger Approval Processes when an Opportunity stage is set to "Approval Requested". Here is the snipped of code from my APEX trigger that invoke the Approval Process -
But I get the following error when I create an Opportunity and set stage = "Approvals Requested". Any idea what is it that I am doing wrong here.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger insertionOrderTrigger caused an unexpected exception, contact your administrator: insertionOrderTrigger: execution of BeforeUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process found.: Trigger.insertionOrderTrigger.invokeApprovalProcess: line 141, column 5
I am trying to programatically trigger Approval Processes when an Opportunity stage is set to "Approval Requested". Here is the snipped of code from my APEX trigger that invoke the Approval Process -
void invokeApprovalProcess(Opportunity o){
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setObjectId(o.id);
req.setComments('Submitting Opportunity '+o.Name+' for approval');
System.debug('Submitting Opportunity '+o.Name+' for approval');
Approval.process(req);
}
But I get the following error when I create an Opportunity and set stage = "Approvals Requested". Any idea what is it that I am doing wrong here.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger insertionOrderTrigger caused an unexpected exception, contact your administrator: insertionOrderTrigger: execution of BeforeUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process found.: Trigger.insertionOrderTrigger.invokeApprovalProcess: line 141, column 5
HuluSFAdmin
Figured it out - I set up the trigger on "Before Update" of Opportunity instead of "After Update"