Loading
Salesforce Enforces New Security Requirements in Summer 2026Read More
Extend Salesforce with Clicks, Not Code
Construct Effective Custom URL Buttons and Links

Construct Effective Custom URL Buttons and Links

Use these methods to construct effective custom URL buttons and links.

Required Editions

Available in: Salesforce Classic

Custom buttons and links are available in: All Editions

Visualforce pages and s-controls are available in: Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, and Developer Editions

Use Merge Fields to Pass Salesforce Data

For example, you can create custom links that search Google for an account name or look up an address on a map.

http://google.com/search?q={!Account.Name}
http://maps.google.com?q={!Account.ShippingStreet} {!Account.ShippingCity} {!Account.ShippingState} {!Account.ShippingPostalCode}
Note
Note Custom links don’t support data type conversion. When creating custom links to pass data from one Salesforce field to another, the data must match the data type of the fields in which you’re placing it. For example, if you have numeric data, you must pass it to a numeric field.

Substitute Symbols for Certain Characters

Substitute symbols for certain characters or use URLENCODE().

Due to the World Wide Web Consortium’s URL encoding standards (W3C), certain unsafe characters, such as spaces and punctuation marks, can’t be passed through a URL. Custom buttons and links escape these characters, so you don’t have to URL-encode them.

If you must encode your URL, use the URLENCODE() function in the merge field like so: {!URLENCODE(text)} and replace text with the merge field or text string that you want to encode.

For example: If the merge field foo__c contains <B>Mark's page<b>, {!URLENCODE(foo_c)} results in: %3CB%3EMark%27s%20page%3C%2Fb%3E.

Link to Visualforce Pages

To link to a Visualforce page, use URLFOR() with the relative path to the page, which is /apex/PageName. For example, to link to a Visualforce page called MissionList that isn’t associated with a record, use the following syntax.

{! URLFOR( “/apex/MissionList” ) }

When you use URLFOR() with a Visualforce page, and you want to pass a record ID into the page, you must pass the ID in as a parameter.

{! URLFOR( “/apex/Mission”, null, [id=Mission__c.Id] ) }

Point to Salesforce Pages

Use the $Action global variable and URLFOR() to point to Salesforce pages.

When creating a custom button or link that points to a page in Salesforce, use the $Action global variable to construct the link, instead of pasting in the path to the page. Then, if your organization is moved to another server or the URL to the page changes, the link still points to the right place.

To construct the link, use the URLFOR() formula function with the $Action variable.

{!URLFOR( $Action.Case.NewCase, Account.Id )}

This custom link on the Account object opens the New Case form, creating the case as a child of the account record. You can use this process for any object that has a lookup to the Account object. To create a record that isn’t a child of another record, or if two objects have no relationship, use $ObjectType.ObjectName as the second argument. For example:

{!URLFOR( $Action.Case.NewCase, $ObjectType.Case )}

$Action global variables expect either a record ID or the $ObjectType. For example, these formulas create links to the tab and detail page for an account, respectively.

{!URLFOR( $Action.Account.Tab, $ObjectType.Account )}
{!URLFOR( $Action.Account.View, Some_Account_Lookup__c.Id )}

The URLFOR() function takes additional optional arguments that get passed into the destination as query string parameters. You can use these arguments when overriding a standard action with a Visualforce page to pass in the additional parameters needed by the Visualforce page or its controller. For example, if when closing a case you want to change the value of a custom field on the case called Actual Delivery Date to today, you could use:

{!URLFOR($Action.Case.CloseCase, Case.Id, [ actualDeliveryDate=TODAY()] )}

You can then override the Close Case action with a Visualforce page and handle setting the value of the Actual Delivery Date field either in that Visualforce page or its controller. See Using Query String Parameters in a Visualforce Page for more information.

Point to Other Pages in Lightning Experience

Use these Lightning-friendly URL button and link methods to point to other pages in Lightning Experience.

Custom URL Button or Link Lightning Experience Behavior

External URL

www.google.com
URL opens in new tab

Relative Salesforce URL, View

/{!Account.Id}
Record home page opens in existing tab

Relative Salesforce URL, Edit

/{!Account.Id}/e
Edit overlay pops up on the existing page

Relative Salesforce URL, List

/001/o
Object home page opens in existing tab

$Action URL, View

{!URLFOR($Action.Account.View, Account.Id)}
Record home page opens in existing tab

$Action URL, Edit

{!URLFOR($Action.Account.Edit, Account.Id)}
Edit overlay pops up on the existing page
Note
Note Using URL custom buttons to pass parameters to standard pages in Salesforce Classic, such as prepopulating fields when creating a record, doesn’t work in the Salesforce mobile app.
 
Loading
Salesforce Help | Article