Skip to content

Instantly share code, notes, and snippets.

@forcementor
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save forcementor/52b5098e93b5bb90f2b6 to your computer and use it in GitHub Desktop.
Save forcementor/52b5098e93b5bb90f2b6 to your computer and use it in GitHub Desktop.
This is a Stateless Action Page that demos the capability of the salesforce.com URLFOR() function from a Visualforce page to perform navigation based actions on various sObjects. Note there is NO StandardController, specified sObject or apex:form component. You MUST set the variables for an Account and Contact ID from your org. The first column …
<!--
=========================================================================================
Name: StatelessActionDemo
Type: Visualforce Page
Purpose: Demonstration of URLFOR() functionality
Created by: Don Robins - www.ForceMentor.com
Created on: October 1, 2013 - (c) 2013 Outformations, Inc.
Rev # Revised on Revised by Revision Description
----- ---------- -------------------------------------
1.0 10/01/2013 Don Robins Initial Release for 'Visualforce In Action' by salesforce.com
=========================================================================================
Note there is NO StandardController, specified sObject or apex:form component
You MUST set the variables for an Account and Contact ID from your org
The first column contains a functional $Action link
The second column shows the Generated URL, note the encoding and any parameters
Review comments above each link regarding the content of the generated URL displayed
=========================================================================================
-->
<apex:page >
<apex:pageBlock title="Stateless Action Demo">
<!--Variables for Account and Contact ids - set these from recods in your org-->
<apex:variable var="contactId" value="003A0000005czjQ" />
<apex:variable var="accountId" value="001A0000005HjZL" />
<apex:outputLabel>Specified Account: {!accountId}</apex:outputLabel>
<br/>
<apex:outputLabel>Specified Contact: {!contactId}</apex:outputLabel>
<br/>
<br/>
<apex:panelGrid columns="2" border="1">
<apex:outputLabel style="font-weight: bold;" >Action</apex:outputLabel>
<apex:outputLabel style="font-weight: bold;" >Generated URL</apex:outputLabel>
<!--New Account
Note there is NO second parameter required on the URLFOR()
Note the standard view Frontdoor URL usage: https://naX.salesforce.com/{ID}/e
The generated retURL redirects back to this page
-->
<apex:outputLink value="{!URLFOR($Action.Account.New)}">New Account</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Account.New)}
</apex:outputLabel>
<!--Change the Account Owner
This is an example of an Account specific $Action
Note the second is the record Id
Note the standard view Frontdoor URL usage: https://naX.salesforce.com/{ID}
Note the optional appended '/a'
The generated retURL redirects back to this page
See the Visualforce documentation for all of the sObject specific $Actions
-->
<apex:outputLink value="{!URLFOR($Action.Account.ChangeOwner, accountId)}">Change Account Owner</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Account.ChangeOwner, accountId)}
</apex:outputLabel>
</apex:panelGrid>
<p/>
<apex:panelGrid columns="2" border="1">
<apex:outputLabel style="font-weight: bold;" >Action</apex:outputLabel>
<apex:outputLabel style="font-weight: bold;" >Generated URL</apex:outputLabel>
<!--New Contact
Note the $Action is NewContact NOT New!
Note there is NO second parameter required on the URLFOR() function
Note the standard new Frontdoor URL usage: https://naX.salesforce.com/{PREFIX}/e
The generated retURL redirects back to this page
-->
<apex:outputLink value="{!URLFOR($Action.Contact.NewContact)}">New Contact</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Contact.NewContact)}
</apex:outputLabel>
<!--View the Contact
Note the standard view Frontdoor URL usage: https://naX.salesforce.com/{ID}
Note the optional appended '/d'
The generated retURL redirects back to this page
-->
<apex:outputLink value="{!URLFOR($Action.Contact.View, contactId)}">View Contact</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Contact.View, contactId)}
</apex:outputLabel>
<!--Edit the Contact, but return to the Contacts standard View page
Note the standard edit Frontdoor URL usage: https://naX.salesforce.com/{ID}/e
The custom retURL redirects to the standard view page.
-->
<apex:outputLink value="{!URLFOR($Action.Contact.Edit, contactId, [retURL=URLFOR('/' + contactId)])}">Edit Contact</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Contact.Edit, contactId, [retURL=URLFOR('/' + contactId)])}
</apex:outputLabel>
<!--Delete the Contact
Note the URL calls https://naX.salesforce.com/setup/own/deleteredirect.jsp?delID={ID}
The generated retURL redirects to the sObject tab /003/o using ID Prefix for Contact
An additional parameter _CONFIRMATIONTOKEN= is generated for additional security
-->
<apex:outputLink value="{!URLFOR($Action.Contact.Delete, contactId)}">Delete Contact</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Contact.Delete, contactId)}
</apex:outputLabel>
<!--Clone the Contacts
Note the standard edit Frontdoor URL usage: https://naX.salesforce.com/{ID}/e
There is an additional parameter to activate the cloning: clone=1
The auto generated retURLback to this page
-->
<apex:outputLink value="{!URLFOR($Action.Contact.Clone, contactId)}">Clone Contact</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Contact.Clone, contactId)}
</apex:outputLabel>
<!--Manual Sharing for the Contact
Note the URL calls https://naX.salesforce.com/p/share/ConSharingDetail?parentId={ID}
The parentId is the Id of this record to be shared
There is no retURL generated unless you add a custom one, redirect will be the standard sObject view
Sharing for the sObject must be set to ReadOnly or Private or an error will display
-->
<apex:outputLink value="{!URLFOR($Action.Contact.Share, contactId)}">Share Contact</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Contact.Share, contactId)}
</apex:outputLabel>
<!--Go to the Contact Home Tab
Note the second parameter on the URLFOR() function is required for $ObjectType
Note the URL calls https://naX.salesforce.com/{PREFIX}/o using ID Prefix for Contact
The generated retURL redirects back to this page
-->
<apex:outputLink value="{!URLFOR($Action.Contact.Tab, $ObjectType.Contact)}">Contact Home Tab</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Contact.Tab, $ObjectType.Contact)}
</apex:outputLabel>
<!--Goto the List for Contact
Note the second parameter on the URLFOR() function is required for $ObjectType
Note the URL calls https://naX.salesforce.com/{PREFIX}/l using ID Prefix for Contact
The generated retURL redirects back to this page
-->
<apex:outputLink value="{!URLFOR($Action.Contact.List, $ObjectType.Contact)}">Contact List</apex:outputLink>
<apex:outputLabel >
{!URLFOR($Action.Contact.List, $ObjectType.Contact)}
</apex:outputLabel>
</apex:panelGrid>
</apex:pageBlock>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment