You need to sign in to do that
Don't have an account?

Approve/Reject the record in apex class
Hi All,
I have custom Submit For Approval, Approve and Reject Buttons on the record detail page.
I have created a Approval Process .I want to call this Approval Process to execute upon clicking custom 'Submit for Approval' Button.This I am able to acheive by following code.
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setObjectId(recordid);
Now when user clicks on custom 'Approve' button the approval request record created above should be approved.
If Can anyone share a sample of code to acheive this it will be helpful.
Thanks,
Srilakshmi B
Here is sample code
You can see comple example here : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_process_example.htm
All Answers
Here is sample code
You can see comple example here : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_process_example.htm
Where did -- newWorkItemIds.get(0) come from in the prior code?
Go through the URL.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_process_example.htm
You will find your answer there.
Regards,
Kamlesh
The problem with that example is that is shows how it's done if the program is going to create and approve the process in one fell swoop.
It doesn't show how to find a process that's pending and approve it.
did any body get an answer for the above question?
I stumbled upon this page looking for an answer for this and eventually found the answer at this page: http://shivasoft.in/blog/salesforce/dynamic-approval-process-based-on-the-apex-and-trigger/
Basically, you want to query out from ProcessInsanceWorkitem for your ObjectID. This was accomplished by this blogger with the following utility function:
Hopefully this helps someone else looking for the same info. A shame that SFDC doesn't include this in the example as I think this case is much more general than doing a submit for approval and appoving all in the same area of code.