5

I have a custom object, Site, with an action that creates a new child record, Holiday, for a Site. I have a Visualforce page that uses the Site standard controller to display a limited subset of Site fields. I'd like to make use of that action in the Visualforce page. Is there a way to surface an object's actions in a Visualforce page? I tried the following,

<apex:commandButton action="{!New_Holiday}" value="New Holiday" id="theButton"/>

but I'm getting an "unknown method..." error which makes me think I'd need to make a controller extension (and code for the action). I can created the extension if that's how I need to do this, but I'm hoping to find a way to use an existing action.

I've found plenty of info about using visualforce pages as actions, but nothing yet about surfacing actions in VF pages.

Note: I'm mainly intending this for use in Salesforce1, but it won't bother me if this action is available in regular Salesforce and Salesforce1.

Edited to add The following code works:

<apex:commandButton action="{!URLFOR($Action.SiteProgram__c.New_Holidaybtn)}" value="Create New Holiday" id="whatevs"></apex:commandButton>

It appears that object-specific actions are not accessible via $Action, but buttons and links are.

8

The new action doesn't appear in the list of Standard Controller Actions but you should be able to use a global action like:
<apex:outputLink value="{!URLFOR($Action.Holiday__c.New)}">Create New Holiday</apex:outputLink>

You could also create an object specific action on Site by following these steps from the Publishers Action Implementation Guide:

To create object-specific actions:
1. From Setup, click Customize, choose the object for which you want to create an action, and click Buttons, Links, and Actions.
2. Click New Action.
3. Select the type of action you want to create.
4. Customize the action:
• For a Create a Record action, select the type of object to create.
◊ If there’s more than one record type for that object, select the one you want to use for records created through this action.
◊ If there’s more than one relationship between the object on which you’re creating the action and the target object, select the field you want to populate automatically when a record is created. (For objects with only one relationship, the Relationship Field is set by default.)

6
  • After reading your answer, I had hopes that something like "<apex:outputLink value="{!URLFOR($Action.SiteProgram__c.New_Holiday)}">Create New Holiday</apex:outputLink>" might work for object-specific links, but using the name of the action after the object name in the outputlink does not work for me.
    – Jagular
    Aug 25 '14 at 20:08
  • My apologies, I misunderstood your question, that will work for custom buttons, but not actions. I did some digging and found this question... salesforce.stackexchange.com/questions/40312/… is this what you are trying to do?
    – Jenny B
    Aug 26 '14 at 2:27
  • I'll give it a try as a custom button and let you know what I find.
    – Jagular
    Aug 26 '14 at 2:43
  • I tested the url for with a custom button and that does work but I couldn't get it to work with an action.
    – Jenny B
    Aug 26 '14 at 2:50
  • Yes, setting this up as a button works. There's one thing still missing. My "{!varname}" values from the button don't get filled in. I should probably make how to get those right a separate question.
    – Jagular
    Aug 26 '14 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.