• skm
  • 10 Points
  • Member since 2009

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2
Hi, I'm trying to perform an approval action through APEX code, in an extended controller.  

First I do a Submit for Approval, overwriting the standard one with a visualforce custom button. Here is the code in my extended controller:


public PageReference submitApproval() { // Create an approval request for the account Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for approval.'); req1.setObjectId(purchaseRequisitionObj.id); // Submit the approval request for the account Approval.ProcessResult result = Approval.process(req1); return Page.PR_Detail_VF; }

After that event, the object left in "Pending" approval state. Then in my detail visualforce page, for specific cases, I have a "Direct Approval" button. That button should perform the instance approval changing its state to "Approved". Here is where I'm stuck, because I can not find the way to get the WorkitemId of the request. I mean the workitemId of the instance I asynchronously approved before. This is the code:


public PageReference directApproval() { // Instantiate the new ProcessWorkitemRequest object and populate it Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest(); req2.setComments('Direct approval by requester'); req2.setAction('Approve'); req2.setNextApproverIds(new Id[] {UserInfo.getUserId()}); req2.setWorkitemId("FROM WHERE I CAN GET THIS ID??"); // Submit the request for approval Approval.ProcessResult result2 = Approval.process(req2); return Page.PR_Detail_VF; }


Any cue will be highly appreciated. Many thanks in advance Fernando.-


  • July 14, 2009
  • Like
  • 0
I need to create several approvals on an Opportunity before it is marked as "Closed Won".

The approvals needed are the following -
  1. Sales Manager to approve any discounts of products
  2. Inventory Mgr to approve availability of products
  3. Finance to approve pricing & discounts of products as well.

These approvals can happen in parallel by different users belonging to the 3 different divisions - Sales, Finance, and Operations.

I tried creating multiple Approval Processes for Sales, Inventory and Finance but since they are all associated with the Opportunity object - so only 1 of the Approval process is getting triggered. Using Approval Steps make it a serial process?

Any idea how I could implement this?