Salesforce Tips: Using Formula to Display Fields from Related Object

October 8, 2012 / Tony / Comments Off on Salesforce Tips: Using Formula to Display Fields from Related Object

A formula can be used to display a field from a related object. Following examples show how it can be done:

1. One level relationship

ExampleWe have two custom objects with Master-Detail Relationship, Candidate (parent) and Interview (child) and we want to display the Candidate’s Phone value in the Interview record.Here are the steps on how we can do it:

– In the Interview object, we create a Formula type field called Candidate’s Phone.

iii. Click Insert and we will get this expression, ” Candidate__r.Phone__c ” in the editor box.

– Every time we modify the Phone value in Candidate, the updated value will be reflected in the corresponding interview record as well.

2. Multi-level relationship (two or more related objects)

Example
We will use the same scenario above, with an additional custom object called Session being the child to Interview object. This time, we want to display the Candidate’s Phone value in the Session record as well.

The steps to do this is much similar to the above:

– In the Session object, we will create a Formula type field called Candidate’s Phone.

iii. Click Insert and we will get this expression, “Interview__r.Candidate__r.Phone__c” in the editor box.

There are some prerequisites to be fulfilled in order to get this working:

This applies only to parent-child relationship object (Lookup Relationship or Master-Detail Relationship).

The formula output data type must be the same as the input type. We will talk more about this in the next section, FAQs.

Some useful FAQs

1. Input and output data type:
We may want to retrieve unique field type like Picklist, Checkbox, etc. We will need to manipulate the output field type.
Here are some suggestion to get the value we want:
– For Picklist field: TEXT(Candidate__r.Location__c)