Approval Process using Apex

In order to use apex code to submit the record for Approval process, we have to first create Approval process in Create --> Workflow & Approvals.


Sample code:

    void submit(Id localId)
    {
        // Create an approval request for the account
   
        Approval.ProcessSubmitRequest req1 =
            new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setObjectId(localId);
       
        // Submit the approval request for the account
   
        Approval.ProcessResult result = Approval.process(req1);
       
        // Verify the result
   
        System.assert(result.isSuccess());
       
        System.assertEquals(
            'Pending', result.getInstanceStatus(),
            'Instance Status'+result.getInstanceStatus());       

    }


Visit the below link to get more details

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_ProcessRequest.htm|StartTopic=Content%2Fapex_ProcessRequest.htm|SkinName=webhelp

Cheers!!!

No comments:

Post a Comment