---
schema_version: "1"
id: cec62fa6f30a792b0fb014970e4b7120111a198e55d081bfd2637545e39d6566
title: Visualforce Pages as Object-Specific Custom Actions
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/custom_actions_vf_pages_for_object_actions.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.custom_actions_vf_pages_for_object_actions.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: f9022f4dd9df80f3827b327b4ababb5f596db15e29c7dd5105115898283154ca
description: 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.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# 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

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col style="width:100%"></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Group</strong>, <strong>Professional</strong>, <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, <strong>Contact Manager</strong>, <strong>Database.com</strong>, and <strong>Developer</strong> Editions</td></tr></tbody></table>

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.

```markup
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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_note.png)

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](https://help.salesforce.com/s/articleView?id=platform.custom_actions_vf_pages_for_global_actions.htm&release=264.0.0&type=5)**  
    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](https://help.salesforce.com/s/articleView?id=platform.custom_actions_vf_pages_remove_pub_header.htm&release=264.0.0&type=5)**  
    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.

#### See Also

- [Visualforce Pages as Global Custom Actions](https://help.salesforce.com/s/articleView?id=platform.custom_actions_vf_pages_for_global_actions.htm&release=264.0.0&type=5 "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.")
- [Create Object-Specific Quick Actions](https://help.salesforce.com/s/articleView?id=platform.creating_object_specific_actions.htm&release=264.0.0&type=5 "Object-specific actions let users create records with automatic relationships to other records, make updates to specific records, and interact with records in ways that you define.")
- [Quick Actions](https://help.salesforce.com/s/articleView?id=platform.actions_overview.htm&release=264.0.0&type=5 "Quick actions enable users to do more in Salesforce and in the Salesforce mobile app. With custom quick actions, you can make your users’ navigation and workflow as smooth as possible by giving them convenient access to information that’s most important. For example, you can let users create or update records and log calls directly in their Chatter feed or from their mobile device.")