0

I have created an Approval Process on OSR__c object. Due to some sudden changes in the requirement, I need to call that approval process from an apex class. I saw the various posts regarding automatic submission/approval/rejection of the record but I dont need that much. Only thing I need is, how to call the approval process(already present in the org) using an apex class ?

Any suggestion/advice on this is really helpful !! Thanks in Advance !

1 Answer 1

3

I assume you want to submit the approval request? Did this not help?

// Create an approval request for the account
        Approval.ProcessSubmitRequest req1 = 
            new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setObjectId(a.id);
        
        // Submit on behalf of a specific submitter
        req1.setSubmitterId(user1.Id); 
        
        // Submit the record to specific process and skip the criteria evaluation
        req1.setProcessDefinitionNameOrId('PTO_Request_Process');
        req1.setSkipEntryCriteria(true);
        
        // Submit the approval request for the account
        Approval.ProcessResult result = Approval.process(req1);

Possible duplicate of this question.

2
  • But my question is, Why will I create an approval request or submit on behalf of others or submit for approval from code ? All this I am doing from my Front end org. I just need to call it from apex class. Is it not as easy as we call a class or method like this : (className.methodName(); ) ???
    – Deep
    Dec 11, 2020 at 10:41
  • I don't know whether I completely get what you are trying to do. All we do finally is ` Approval.process(req)` - similar to what you mentioned. Rest of the statements is just the ceremony to send relevant arguments (setting a few things in the object before invoking the method). I don't know if there is any other way of shortening the call. Dec 11, 2020 at 12:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .