Understanding Global Variables
S-controls and formulas available in: Contact Manager, Group, Professional, Enterprise, Unlimited, and Developer Editions
Custom buttons and links are available in: All Editions
Visualforce available in: Contact Manager, Group, Professional, Enterprise, Unlimited, and Developer Editions
$Profile global merge field type available in: Enterprise, Unlimited, and Developer Editions
|
User Permissions Needed | |
---|---|
To create, edit, and delete custom s-controls, formulas, or Visualforce pages: | “Customize Application” |
Components such as s-controls, custom buttons, custom links, formulas, and Visualforce pages allow you to use special merge fields to reference the data in your organization. Use the following global variables when choosing a merge field type to add to your custom component:
$Action
Description: | A global merge field type to use when referencing standard Salesforce actions such as displaying the Accounts tab home page, creating new accounts, editing accounts, and deleting accounts. Use action merge fields in LINKTO and URLFOR functions to reference the action selected. |
Use: |
|
S-Control Example: | The s-control below references the standard action for creating new accounts in the $Action.Account.New merge field.<html> <body> {!LINKTO("Create a New Account", $Action.Account.New, $ObjectType.Account)} </body> </html> |
VisualforceExample: | <apex:outputLink value="{!URLFOR($Action.Account.New)}">Create New Account</apex:outputLink> |
Tips: | This global variable is only available for custom buttons and links, s-controls, and Visualforce pages. |
$Api
Description: | A global merge field type to use when referencing API URLs. |
Use: |
|
S-Control Example: | The custom formula field below calls a service to replace the SIC code. Replace myserver with the name of your server.HYPERLINK("https://www.myserver.com/mypage.jsp" & "?Username=" & $User.Username & "&crmSessionId=" & GETSESSIONID() & "&crmServerUrl=" & $Api.Partner_Server_URL_90 & "&crmObjectId=" & Id & "&crmFieldUpdate=sicCode", "Update SIC Code") |
VisualforceExample: | Use dot notation to return the session ID.{!$Api.Session_ID} |
Tips: | This global variable is only available for formula fields, s-controls, custom buttons and links, and Visualforce pages. |
$Component
Description: | A global merge field type to use when referencing a Visualforce component. |
Use: | Each component in a Visualforce page has its own id attribute. When the page is rendered, this attribute is the same as the Document Object Model (DOM) ID.Use $Component.Id in JavaScript to reference a specific component on a page. |
VisualforceExample: | function beforeTextSave() { document.getElementById('{!$component.msgpost}').value = myEditor.getEditorHTML(); } |
Tips: | This global variable is only available for Visualforce pages. |
$componentLabel
$CurrentPage
$Label
$Label.Site
$ObjectType
Description: | A global merge field type to use when referencing standard or custom objects such as accounts, cases, or opportunities as well as the value of a field on that object. Use object type merge fields in LINKTO,GETRECORDIDS, and URLFOR functions to reference a specific type of data or the VLOOKUP function to reference a specific field in a related object. |
Use: |
|
Custom Button Example: | The custom list button below references the cases standard object in the$ObjectType.Case merge field.{!REQUIRESCRIPT ("/soap/ajax/13.0/connection.js")} var records = {!GETRECORDIDS($ObjectType.Sample)}; var newRecords = []; if (records[0] == null) { alert("Please select at least one row") } else { for (var n=0; n<records.length; n++) { var c = new sforce.SObject("Case"); c.id = records[n]; c.Status = "New"; newRecords.push(c); } result = sforce.connection.update(newRecords); window.location.reload(); } |
Validation Rule Example: | This example checks that a billing postal code is valid by looking up the first five characters of the value in a custom object called Zip_Code__c that contains a record for every valid zip code in the US. If the zip code is not found in the Zip_Code__c object or the billing state does not match the corresponding State_Code__c in the Zip_Code__c object, an error is displayed.AND( LEN(BillingPostalCode) > 0, OR(BillingCountry = "USA", BillingCountry = "US"), VLOOKUP( $ObjectType.Zip_Code__c.Fields.State_Code__c, $ObjectType.Zip_Code__c.Fields.Name, LEFT(BillingPostalCode,5)) <> BillingState ) |
VisualforceExample: | The following example retrieves the label for the account namefield:{!$ObjectType.account.fields.name.label} |
Tips: | This global variable is available in Visualforce pages, custom buttons and links, s-controls and validation rules. |
$Organization
Description: | A global merge field type to use when referencing information about your company profile. Use organization merge fields to reference your organization's city, fax, ID, or other details. |
Use: |
|
Validation Rule Example: | Use organization merge fields to compare any attribute for your organization with that of your accounts. For example, you may want to determine if your organization has the same country as your accounts. The validation formula below references your organization's country merge field and requires a country code for any account that is foreign.AND($Organization.Country <> BillingCountry, ISNULL( Country_Code__c ) ) |
VisualforceExample: | Use dot notation to access your organization's information. For example, to retrieve the street and state of your organization, use the following:{!$Organization.Street} {!$Organization.State}
Note that you cannot use the {!$Organization.UiSkin} in Visualforce.
|
Tips: | The organization merge fields get their values from whatever values are currently stored as part of your company information in Salesforce. |
$Page
Description: | A global merge field type to use when referencing a Visualforce page. |
Use: | Use this expression in a Visualforce page to access another Visualforce page. |
Visualforce Example: | |
Tips: | This global variable is only available for Visualforce pages. |
$Profile
Description: | A global merge field type to use when referencing information about the current user's profile. Use profile merge fields to reference information about the user's profile such as license type or name. | ||||||||||||||||||||||||
Use: |
| ||||||||||||||||||||||||
Validation Rule Example: | The validation rule formula below references the profile name of the current user to ensure that only the record owner or users with this profile can make changes to a custom field called Personal Goal:AND( ISCHANGED( Personal_Goal__c ), Owner <> $User.Id, $Profile.Name <> "Custom: System Admin" ) | ||||||||||||||||||||||||
Visualforce Example: | To return the current user's profile, use the following:{$Profile.Name} | ||||||||||||||||||||||||
Tips: |
|
$RecordType
Description: | A global merge field to use when referencing a record type. |
Use: | Add $RecordType manually to your s-control. |
VisualforceExample: | To return the ID of the current record type, use the following:{$RecordType.Id} |
Tips: |
|
$Request
Description: | A global merge field to use when referencing a query parameter by name that returns a value. |
Use: | Add $Request manually to your s-control. |
S-Control Example: | The snippet below, named Title_Snippet, requires two input parameters: titleTheme and titleText. You can reuse it in many s-controls to provide page title and theme in your HTML.<h2 class=”{!$Request.titleTheme}.title”>{!$Request.titleText}</h2>
The s-control below calls this snippet using the INCLUDE function, sending it the parameters for both the title and theme of the HTML page it creates.
<html> <head> </head> <body> {! INCLUDE($SControl.Title_Snippet, [titleTheme = "modern", titleText = "My Sample Title"]) } ... Insert your page specific content here ... </body> </html> |
Tips: | Do not use $Request in Visualforce pages to reference query parameters. Use $CurrentPage instead. |
$Resource
Description: | A global merge field type to use when referencing an existing static resource by name in a Visualforce page. You can also use resource merge fields in URLFOR functions to reference a particular file in a static resource archive. |
Use: | Use $Resource to reference an existing static resource. The format is $Resource.nameOfResource, such as $Resource.TestImage. |
VisualforceExamples: | The Visualforce component below references an image file that was uploaded as a static resource and given the name TestImage:<apex:image url="{!$Resource.TestImage}" width="50" height="50"/>
To reference a file in an archive (such as a .zip or .jar file), use the URLFOR function. Specify the static resource name that you provided when you uploaded the archive with the first parameter, and the path to the desired file within the archive with the second. For example:
<apex:image url="{!URLFOR($Resource.TestZip, 'images/Bluehills.jpg')}" width="50" height="50"/> |
Tips: | This global variable is only available for Visualforce pages. |
$SControl
Description: | A global merge field type to use when referencing an existing custom s-control by name. Use s-control merge fields in LINKTO, INCLUDE, and URLFOR functions to reference one of your custom s-controls. |
Use: |
|
S-Control Example: | The s-control below references the snippet in the $Scontrol.Header_Snippet merge field:<html> <body> {! INCLUDE($SControl.Header_Snippet, [title = "My Title", theme = "modern"])} </body> </html> |
VisualforceExample: | The following example shows how to link to an s-control named HelloWorld in a Visualforce page:<apex:page> <apex:outputLink value="{!$SControl.HelloWorld}">Open the HelloWorld s-control</apex:outputLink> </apex:page>
Note that if you simply want to embed an s-control in a page, you can use the <apex:scontrol> tag without the $SControl merge field. For example:
<apex:page> <apex:scontrol controlName="HelloWorld" /> </apex:page> |
Tips: |
|
$Site
Description: | A global merge field type to use when referencing information about the current Force.com site. | ||||||||||||||||||||||||||||||
Use: |
Use dot notation to access information about the current Force.com site. Note that only the following site fields are available:
| ||||||||||||||||||||||||||||||
Visualforce Example: | The following example shows how to use the $Site.Template merge field:<apex:page title="Job Application Confirmation" showHeader="false" standardStylesheets="true"> <!-- The site template provides layout & style for the site --> <apex:composition template="{!$Site.Template}"> <apex:define name="body"> <apex:form> <apex:commandLink value="<- Back to Job Search" onclick="window.top.location='{!$Page.PublicJobs}';return false;"/> <br/> <br/> <center><apex:outputText value="Your application has been saved. Thank you for your interest!"/></center> <br/> <br/> </apex:form> </apex:define> </apex:composition> </apex:page> | ||||||||||||||||||||||||||||||
Tips: | This global variable is available in Visualforce pages, email templates, and s-controls. |
$System.OriginDateTime
Description: | A global merge field that represents the literal value of 1900-01-01 00:00:00. Use this global variable when performing date/time offset calculations or to assign a literal value to a date/time field. |
Use: |
|
Formula Example: | The example below illustrates how to convert a date field into a date/time field. It uses the date in the OriginDateTime merge field to get the number of days since a custom field called My Date Field. Then, it adds the number of days to the OriginDateTime value.$System.OriginDatetime + ( My_Date_Field__c - DATEVALUE($System.OriginDatetime) ) |
VisualforceExample: | The following example calculates the number of days that have passed since 1900:{!NOW() - $System.OriginDateTime} |
Tips: | This global variable is available in Visualforce pages, default values, field updates, formula fields, s-controls, and validation rules. |
$User
Description: | A global merge field type to use when referencing information about the current user. User merge fields can reference information about the user such as alias, title, and ID. |
Use: |
|
Validation Rule Example: | The validation rule formula below references the ID of the current user to determine if the current user is the owner of the record. Use an example like this to ensure that only the record owner or users with an administrator profile can make changes to a custom field called Personal Goal:AND( ISCHANGED( Personal_Goal__c ), Owner <> $User.Id, $Profile.Name <> "Custom: System Admin" ) |
VisualforceExample: | The following example displays the current user's company name, as well as the status of the current user (which returns a Boolean value).<apex:page> <h1>Congratulations</h1> This is your new Apex Page <p>The current company name for this user is: {!$User.CompanyName}</p> <p>Is the user active? {!$User.isActive}</p> </apex:page> |
Tips: |
|
$User.UITheme and $User.UIThemeDisplayed
Description: | These global merge fields identify the Salesforce look and feel a user sees on a given Web page.
The difference between the two variables is that $User.UITheme returns the look and feel set by the user, while $User.UIThemeDisplayed returns the actual look and feel. For example, a user may have the permissions to see the new user interface theme look and feel, but if they are using a browser that doesn't support that look and feel, $User.UIThemeDisplayed returns a different value.
|
Use: | Use these variables to identify the CSS used to render Salesforce web pages to a user. Both variables return one of the following values:
|
VisualforceExample: | The following example shows how you can render different layouts based on a user's theme:<apex:page> <apex:pageBlock title="My Content" rendered="{!$User.UITheme == 'Theme2'}"> // this is the old theme... </apex:pageBlock> <apex:pageBlock title="My Content" rendered="{!$User.UITheme == 'Aloha'}"> //this is the new theme ... </apex:pageBlock> </apex:page>
The section “Styling Visualforce Pages” in the Visualforce Developer's Guide provides more information on how to use these global variables.
|
$UserRole
Description: | A global merge field type to use when referencing information about the current user's role. Role merge fields can reference information such as role name, description, and ID. |
Use: |
|
Validation Rule Example: | The validation rule formula below references the user role name to validate that a custom field called Discount Percent does not exceed the maximum value allowed for that role:Discount_Percent__c > VLOOKUP($ObjectType.Role_Limits__c.Fields.Limit__c, $ObjectType.Role_Limits__c.Fields.Name, $UserRole.Name) |
Visualforce Example: | {!$UserRole.LastModifiedById} |
Tips: |
|
5 comments:
Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post.
Salesforce Training
you have providing useful coding's i love this post keep updates...
Salesforce training institute in Chennai
Your blog is really awesome and I got some useful information from your blog. This is really useful for me. Thanks for sharing such a informative blog. Keep posting.
Regards..
Cloud Training in Chennai
Nowadays, most of the businesses rely on cloud based CRM tool to power their business process. They want to access the business from anywhere and anytime. In such scenarios, salesforce CRM will ensure massive advantage to the business owners. Amazon Web Services Training in Chennai | Amazon Web Services Training
I’d like to write some material for your blog in exchange for a link back to mine. Please shoot me an email if interested. Thanks.
safety course in chennai
Post a Comment