Loading
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Example: Add an Approval Button on a Record Page

          Example: Add an Approval Button on a Record Page

          Add a button that users can click to submit a record for approval. Let’s see an example for adding a button on the quote page.

          Required Editions

          Available in: Lightning Experience
          Available in: Enterprise, Unlimited, and Developer Editions of Revenue Cloud where Transaction Management is enabled

          To add an approval button, follow the instructions in each of these sections.

          Create an Apex Class

          Follow these steps to create and use the QuoteApprovalController Apex class, which will begin the approval workflows

          1. From Setup, search for and select Apex Classes.
          2. Click New.
          3. In the class editor, enter the Apex code for the class.
            public class QuoteApprovalController {
                private Id quoteId;
                private String userId;
                public String submitterComments { get; set; }
               
                public QuoteApprovalController(ApexPages.StandardController controller) {
                    Quote quote = (Quote) controller.getRecord();
                    quoteId = quote.Id;
                    userId = UserInfo.getUserId();
                }
                
                public void submitQuoteForApproval() {
                    String flowApiName = 'Approval_Autolaunched_Flow';
                    Map<String, Object> inputs = new Map<String, Object>();
                    inputs.put('recordId', quoteId);
                    inputs.put('submitter', userId);
                    inputs.put('submissionComments', submitterComments);
                    Flow.Interview myFlow = Flow.Interview.createInterview(flowApiName, inputs);
                    myFlow.start();
                }
            }
            
          4. Save your changes.

          Create a Visualforce Page

          Follow these steps to create a Visualforce page called QuoteApprovalPage to trigger the Apex class.

          1. From Setup, search for and select Visualforce Pages.
          2. Click New.
          3. Enter QuoteApprovalPage as the label and name.
          4. Select Available for Salesforce mobile apps and Require CSRF protection on GET requests.
          5. In the Visualforce Markup text box, enter Visualforce markup for the page.
            <apex:page standardController="Quote" extensions="QuoteApprovalController" showQuickActionVfHeader="false" lightningStylesheets="true">
                <script>
                    function closePopupWindow() {
                        if (typeof sforce != 'undefined' && sforce && sforce.one) {
                            var quoteId = '{!Quote.Id}';
                            sforce.one.navigateToSObject(quoteId);
                        } else {
                            window.close();
                        }
                    }
                </script>
                <h2 align='center'>
                    Submit for Approval
                </h2>
               <apex:form >
                    <apex:pageBlock >
                        <apex:pageBlockButtons location="bottom">
                            <p align='left'>Enter comments for Approver(s):</p>
                            <p align='center'><apex:inputTextarea value="{!submitterComments}" cols="100"/></p>          
                            <apex:commandButton value="Submit" action="{!submitQuoteForApproval}" oncomplete="closePopupWindow();" /> 
                        </apex:pageBlockButtons>
                    </apex:pageBlock>
                </apex:form>
            </apex:page>
            
          6. Save your changes.
          7. From Setup, search for and select Visualforce Pages.
          8. Click Security against the QuoteApprovalPage.
          9. Add your sales reps profiles to enable access to the Visualforce pages.

          Create a Custom Action

          Follow these steps to create a custom action on an object. For example, let’s create this custom action on the Quote object.

          1. From the Object Manager, search for and select Quote.
          2. Select Buttons, Links, and Actions.
          3. Click New Action and specify these details.
            • Action Type: Custom Visualforce
            • Visualforce Page: QuoteApprovalPage
            • Label: Submit for Approval
            • Name: Submit_for_Approval
          4. Save your changes.

          Modify Page Layout of the Object

          Follow these steps to add the newly created action, Submit for Approval to the page layout of the Quote object.

          1. On the Quote object settings page, click Page Layouts.
          2. Select Quote Layout.
          3. In the palette, click Mobile & Lightning Actions.
          4. Drag Submit for Approval to the Salesforce Mobile and Lightning Experience Actions section in the layout.
          5. Save your changes.
           
          Loading
          Salesforce Help | Article