You need to sign in to do that
Don't have an account?
Sfdc_beginner
Not able to invoke an approval process using trigger
Hi All,
I am trying to invoke an approval process using trigger which in turn is invoked when a user submits a records in a VF form whose approval status is "Submitted for approval". But the approval process is not getting triggered.
The approval process name is Practice_Submission_Approval.and the trigger code is listed below.
trigger PracticeSubmitForApproval on Practice__c (before insert) { for(Practice__c appsub: Trigger.new){ if (appsub.Approval_Status__c == 'Submitted for approval') { appsub = [ select ID from Practice__c where id in :Trigger.new ]; Approval.ProcessSubmitRequest request = new Approval.ProcessSubmitRequest(); request.setComments('Submitting request for approval.'); request.setObjectId(appsub.id); Approval.ProcessResult result = Approval.process(request); System.assert(result.isSuccess()); } } ]
Please correct me if my code is wrong.
Thanks in advance
THere are few changes I will suggest
Hello,
Also advise to use try-catch, as it possible that the process failed when trying to send it.
In this case, the exception message will tell you the reason
try
{
appsub = [ select ID from Practice__c where id in :Trigger.new ];
Approval.ProcessSubmitRequest request = new Approval.ProcessSubmitRequest();
request.setComments('Submitting request for approval.');
request.setObjectId(appsub.id);
Approval.ProcessResult result = Approval.process(request);
System.assert(result.isSuccess());
}
catch(Exception e){
System.debug('#### : failed: ' + e);
}
Following up on the last post - you can debug the entry criteria by looking at the Debug Log 'Workflow' debug trace in case you ahve complex entry criteria