Search code examples
salesforceapex-code

Approval / Reject functionality on custom buttons of object


I am trying to implement the functionality of having the approve and reject buttons on custom button in the object.

I have 2 questions

  1. Can we call apex method from a custom button?
  2. How can we mimic the approval / reject functionality in apex class?

thanks


Solution

  • 1) You'd need to create a VF page which does the work you need and the redirects back to wherever you want you user to be. Described here: http://sfdc.arrowpointe.com/2009/01/08/invoke-apex-from-a-custom-button-using-a-visualforce-page/

    2) Have a look at 2nd half (the req2 part) of this example: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_process_example.htm|StartTopic=Content%2Fapex_process_example.htm|SkinName=webhelp . Then instead of getting the newWorkItemIds.get(0) value from the result, you'd probably want to query it from the ProcessInstanceWorkitem table

    Hope this helps you move on