This post is a part of the daily blog series 

A Tip A Day, daily dosage of learning!


 Day #2 – Display custom popup message while Submitting for Approval

Standard Approval Process Feature: When you setup Standard Approval process on any object, a standard button ‘Submit For Approval’ will be added to the page layout of the object’s record. When you click on the button, it will show a “standard” popup message asking if you want to submit for approval.

Requirement: The requirement is to change that standard message and display a different message “Is the contract signed” and if they click Yes, then the approval process should kick in.  Salesforce doesn’t allow to change the popup message.  Here’s the solution.

Solution:

  • Create a custom button and add this code.  In this code as you can see we are adding a different message – “Submit for Approval only if the contract is signed”.  Then we call a class called “ApprovalProcessor” with a method “submitAndProcessApprovalRequest”
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

if(confirm('Submit for Approval only if the Contract is signed, 
else click Cancel')){ 
    sforce.apex.execute("ApprovalProcessor","submitAndProcessApprovalRequest");
}
  • 2. Create an apex class: Create the Class Approval Processor with a static method. The method calls the Approval process you already setup – PTO_Request_Process.  Below is the code

So, in this process you are still using the standard out of the box functionality of Approval Process but just that the initiation is done from a custom button instead of standard button.

Hope this helps!


Read all other tips of the blog series here – A Tip A Day, daily dosage of learning!

Advertisements