Loading
Salesforce now sends email only from verified domains. Read More
Extend Salesforce with Clicks, Not Code
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
          Visualforce Pages as Object-Specific Custom Actions

          Visualforce Pages as Object-Specific Custom Actions

          A Visualforce page added as a custom action on an object is invoked in the context of a record of that object type. The custom action is passed a specific record ID—the record the user was looking at when the user clicked the custom action. Design the page to act on that specific record type.

          Required Editions

          Available in: both Salesforce Classic and Lightning Experience
          Available in: Group, Professional, Enterprise, Performance, Unlimited, Contact Manager, Database.com, and Developer Editions

          Visualforce pages you create to use as object-specific actions must use a standard object controller. Use controller extensions to add custom code, including @RemoteAction methods you can call using JavaScript remoting.

          Your custom code could do more than make updates to the originating record. For example, the Create Quick Order custom action searches for matching merchandise. It then creates an invoice and line item, all as part of creating an order for a part. That logic occurs in the context of the originating account record—the invoice is related to the account record where the quick order action was invoked.

          The following code sample shows a page designed to be used as a custom action on the account object, so it uses the standard Account controller. This action lets users create cases from account detail pages, and it has a different user interface from standard create actions.

          public with sharing class CreateCaseExtension {
              private final SObject parent;
              public Case theCase {get; set;}
              public String lastError {get; set;}
              
              public CreateCaseExtension2(ApexPages.StandardController controller) {
                  parent = controller.getRecord();
                  theCase = new Case();
                  theCase.accountId = parent.id;
                  lastError = '';
              }
                
              public PageReference createCase() {
                  createNewCase();
                  theCase = new Case();
                  theCase.accountId = parent.id;
                  return null;
              }
                 
               private void createNewCase() {      
                  try {
                      insert theCase;
                      
                      FeedItem post = new FeedItem();
                      post.ParentId = ApexPages.currentPage().getParameters().get('id');
                      post.Body = 'created a case';
                      post.type = 'LinkPost'; 
                      post.LinkUrl = '/' + theCase.id;
                      post.Title = theCase.Subject;
                      insert post;
                  } catch(System.Exception ex){
                     lastError = ex.getMessage();
                  }
              }   
          }
          
          <apex:page standardcontroller="Account" extensions="CreateCaseExtension" showHeader="false">
              <script type='text/javascript' src='/canvas/sdk/js/publisher.js'/> 
              <style>
                  .requiredInput .requiredBlock, .requiredBlock {background-color: white;} 
                  .custompubblock div {display: inline-block;} 
                  .custompublabel {width:54px;} 
              </style>
              <script> 
                  function refreshFeed() { 
                      Sfdc.canvas.publisher.publish({name : 'publisher.refresh', payload : {feed:true}}); 
                  }
              </script>   
              <div> 
                  <apex:form > 
                      <apex:actionFunction action="{!createCase}" name="createCase" rerender="out" 
                      oncomplete="refreshFeed();"/> 
                      <apex:outputPanel id="out" > 
                          <div class="custompubblock"> 
                              <div class="custompublabel">Account:</div><apex:inputField value="{!theCase.accountId}" 
                              style="margin-left:0;"/>&nbsp;&nbsp;&nbsp;
                              <div>Contact:&nbsp;</div><apex:inputField value="{!theCase.contactId}" />
                          </div>
                          <apex:inputField value="{!theCase.description}" style="width:538px;height:92px;margin-top:4px;" />
                          <div class="custompubblock" style="margin-top:5px;"> 
                              <div>Status:&nbsp;</div><apex:inputField value="{!theCase.status}" />&nbsp;&nbsp;&nbsp; 
                              <div>Priority:&nbsp;</div><apex:inputField value="{!theCase.priority}" />&nbsp;&nbsp;&nbsp; 
                              <div>Case Origin:&nbsp;</div><apex:inputField value="{!theCase.origin}" /> 
                          </div> 
                      </apex:outputPanel>
                  </apex:form><br/>
                  <button type="button" onclick="createCase();" 
                  style="position:fixed;bottom:0px;right:0px;padding:5px 10px; 
                  font-size:13px; font-weight:bold; line-height: 
                  18px;background-color:#0271BF;background-image:-moz-linear-gradient(#2DADDC, #0271BF);background-repeat:repeat-x;border-color:#096EB3;" 
                  id="addcasebutton">Create Case</button> 
              </div>  
          </apex:page>
          
          Note
          Note When you redirect to a URL internal to your org, the action dialog closes upon completion or programmatically navigating away. If you set up the redirect to point to an external URL, the behavior can vary because an external URL opens in a new browser tab.

          Requirements for Refreshing Host Pages

          If you want an object-specific or global custom action to refresh the feed on the page that hosts it, the Visualforce page you create to use as that action must:

          • Reference the publisher JavaScript file: <script type='text/javascript' src='/canvas/sdk/js/publisher.js'/>. (Creating custom Visualforce actions doesn’t require the Canvas SDK.)
          • Include this JavaScript call: Sfdc.canvas.publisher.publish({name : 'publisher.refresh', payload : {feed:true}});.
          • Visualforce Pages as Global Custom Actions
            Visualforce pages used as global actions can be invoked in many different places and don’t have a specific record associated with them. They have complete freedom of action, which means it’s up to you to write the code.
          • Hide the Action Header for Visualforce Custom Actions
            When creating a Visualforce page to use as a custom action, you can choose to hide the action’s header. Hiding the action header helps prevent user confusion, especially if you have your own buttons specified in the Visualforce page.
           
          Loading
          Salesforce Help | Article