Advanced Functions

HELLO Salesforce Thinkers, In our previous blog we learned about Summary Functions in Salesforce In this blog we are going to learn about “Advanced Functions”.

We have the following Advanced Functions  in Salesforce.

CURRENCYRATE:

Returns the conversion rate to the corporate currency for the given currency ISO code.

If the currency is invalid, returns 1.0.

Syntax: CURRENCYRATE(currency_ISO_code)

Replace currency_ISO_code with a currency ISO code, such as INR .

GETRECORDIDS :

Returns an array of strings in the form of record IDs for the selected records in a list, such as a list view or related list.

Syntax: {!GETRECORDIDS(object_type)}

Replace object_type with a reference to the custom or standard object for the records you want to retrieve.

Notes :

  • This function is only available in custom buttons, links, and s-controls.
  • Activities are special types of objects. Use {!GETRECORDIDS($ObjectType.Task)} when creating a list task button.
  • Use {!GETRECORDIDS($ObjectType.Event)} when creating an event list button.

IMAGEPROXYURL:

Securely retrieves external images and prevents unauthorized requests for user credentials.

Syntax: {!IMAGEPROXYURL(“\http://abc.com/pic.png)}

Example :

<apex:image value={!IMAGEPROXYURL(\http://abc.com/pic.png)}/>

Replace http://abc.com/pic.png with your image.

Notes:

  • Use IMAGEPROXYURL for all images hosted on servers you don’t control.
  • The rendered image URL can change at any time. Don’t copy and paste it anywhere.
  • Don’t use the rendered image URL outside of Salesforce.

ISCHANGED:

Compares the value of a field to the previous value and returns TRUE if the values are different. If the values are the same, this function returns FALSE.

Syntax: ISCHANGED(field)

Replace field with the name of the field you want to compare.

Notes:

  • This function is available only in Assignment rules, Validation rules, Field updates, Workflow rules if the evaluation criteria is set to Evaluate the rule when a record is: created, and every time it’s edited . Formula criteria for executing actions in Process Builder.
  • We can use the NOT function to reverse the return values of TRUE and FALSE.
  • This function returns FALSE when evaluating any field on a newly created record.
  • If a text field was previously blank, this function returns TRUE when it contains any value.
  • For number, percent, or currency fields, this function returns TRUE when:
  1. The field was blank and now contains any value.
  2. The field was zero and now is blank.
  3. The field was zero and now contains any other value


JUNCTIONIDLIST:

Returns a JunctionIDList based on the provided IDs.

A JunctionIDList is a string array of referenced ID values that represent the many-to-many relationship of an underlying junction entity.

Syntax: JUNCTIONIDLIST(id, id,…)

Replace id with the Salesforce ID you want to use.

Example :

JUNCTIONIDLIST(Case.ContactId)

This formula returns the case’s contact record ID.

When used on the email action for cases, we can use this formula as a predefined value for the To Recipients field. Using this formula as a predefined value for the field ensures that sent emails are always associated with a Salesforce record. In the case feed publisher, users see the contact name instead of the ID or email address.

LINKTO:

Returns a relative URL in the form of a link (href and anchor tags) for a custom s-control or Salesforce page.

Syntax: {!LINKTO(label, target,​id, [inputs], [no override]}

​Replace label with the text for the link, target with the URL, and id with a reference to the record.

Inputs are optional and we can include any additional parameters we want to add to the link.

The no override argument is also optional and defaults to “false”. It applies to targets for standard Salesforce pages such as $Action.Account.New. Replace no override with “true” when you want to display a standard Salesforce page regardless of whether you have defined an override for it elsewhere.

Notes:

This function is only available in custom buttons, links, and s-controls.

REGEX:

Compares a text field to a regular expression and returns TRUE if there is a match. Otherwise, it returns FALSE.

A regular expression is a string used to describe a format of a string according to certain syntax rules.

Syntax: REGEX(text, regex_text)

Replace text with the text field, and regex_text with the regular expression you want to match.

Notes:

  • Regular expression syntax is based on Java Platform SE 6 syntax. However, backslash characters () must be changed to double backslashes (\) because backslash is an escape character in Salesforce.
  • The Salesforce regular expression engine matches an entire string as opposed to searching for a match within a string.
  • This function is available everywhere formulas exist except formula fields and custom buttons and links.


REQUIRESCRIPT:

Returns a script tag with source for a URL we specify.

We can use this function when referencing the Lightning Platform AJAX Toolkit or other JavaScript toolkits.

Syntax: {!REQUIRESCRIPT(url)}

Replace url with the link for the script that is required.

Notes:

  • This function is only available for custom buttons and links that have Content Source set to OnClick JavaScript.
  • Use global variables to access special merge fields for s-controls.
  • Use this function when creating custom buttons or links where you have set Behavior to Execute JavaScript and Content Source to OnClick JavaScript because the script tag must be outside the OnClick code.
  • When working in Visualforce, use INCLUDESCRIPT instead.

URLFOR:

Returns a relative URL for an action, s-control, Visualforce page, or a file in a static resource archive in a Visualforce page.

Syntax: {!URLFOR(target, [id], [inputs], [no override])}

Replace target with the URL or action, s-control, or static resource merge variable, id with an optional reference to the record, and inputs with any optional parameters.

The no override argument is also optional and defaults to “false”. It applies to targets for standard Salesforce pages such as $Action.Account.New. Replace no override with “true” when you want to display a standard Salesforce page regardless of whether you have defined an override for it elsewhere.

Notes:

  • This function is only available in custom buttons, links, s-controls, and Visualforce pages.
  • Use global variables to access special merge fields for actions, s-controls, and static resources.
  • When we override the tab home page for a standard or custom tab, use the tab’s $Action global variable as the target value, and the tab’s object type for the id value. For example, URLFOR($Action.Account.Tab, $ObjectType.Account).


VLOOKUP:

Returns a value by looking up a related value on a custom object similar to the VLOOKUP() Excel function.

Syntax: VLOOKUP(field_to_return, field_on_lookup_object, lookup_value)

Replace field_to_return with the field that contains the value you want returned, field_on_lookup_object with the field on the related object that contains the value you want to match, and lookup_value with the value you want to match.

Notes:

  • The field_to_return must be an auto number, roll-up summary, lookup relationship, master-detail relationship, checkbox, date, date/time, email, number, percent, phone, text, text area, or URL field type.
  • The field_on_lookup_object must be the Record Name field on a custom object.
  • The field_on_lookup_object and lookup_value must be the same data type.
  • If more than one record matches, the value from the first record is returned.
  • The value returned must be on a custom object.
  • You cannot delete the custom field or custom object referenced in this function.
  • This function is only available in validation rules.

INCLUDE:

Returns content from an s-control snippet. Use this function to reuse common code in many s-controls.

Syntax: {!INCLUDE(source, [inputs])}

Replace source with the s-control snippet you want to reference. Replace inputs with any information you need to pass to the snippet.

Notes :

  • Because this function references an s-control snippet and does not copy it, it always runs the latest content of the s-control snippet. Remember that making a change to your s-control snippet affects all INCLUDE functions that refer to it.
  • Use the $Request global variable to access any information inside the snippet.
  • This function is only available in custom buttons, links, and s-controls.

Thanks for reading…

Leave a comment