You need to sign in to do that
Don't have an account?
Adam Rycroft
Help Testing Trigger for After Insert
Hi,
I need help writing a test for the following trigger which submits a record for approval if the created_from_onboarding__c checkbox field is marked true.
I need help writing a test for the following trigger which submits a record for approval if the created_from_onboarding__c checkbox field is marked true.
trigger autoapprovenewhire on Change_of_statusnew__c (after insert) { for(Change_of_statusnew__c changeofstatus : trigger.new){ if(changeofstatus.created_from_onboarding__c == TRUE){ // create the new approval request to submit Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); req.setComments('Submitted for approval. Please approve.'); req.setObjectId(changeofstatus.Id); // submit the approval request for processing Approval.ProcessResult result = Approval.process(req); // display if the reqeust was successful System.debug('Submitted for approval successfully: '+result.isSuccess()); } } }
Why you went with a trigger for submiting a record for approval process, you can do it simply with a process builder.
in process builder, in object select "Change_of_statusnew__c " object and in criteria select "created_from_onboarding__c = true" then in immediate actions select submit for approval then select the desired approval process.
Hope it helps, marks best if it really helps you.
All Answers
Why you went with a trigger for submiting a record for approval process, you can do it simply with a process builder.
in process builder, in object select "Change_of_statusnew__c " object and in criteria select "created_from_onboarding__c = true" then in immediate actions select submit for approval then select the desired approval process.
Hope it helps, marks best if it really helps you.