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.
      i. In Step 3: Enter Formula section, we choose Advanced Formula.
      ii. Click on the Insert Field button above the Formula Editor box. Select “Interview >”, “Candidate >“, and “Phone“.
Figure 1: Accessing parent field from single level child object
      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.
      i. In the Step 3: Enter Formula section, we will choose Advanced Formula to write our expression.
      ii. Click on the Insert Field button above the Formula Editor. Select “Session >”, “Interview >”, Candidate >”, and “Phone’.
Figure 2. Accessing parent field from multi-level child object
      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:
  1. This applies only to parent-child relationship object (Lookup Relationship or Master-Detail Relationship).
  2. 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)
 – For Checkbox field: IF(Candidate__r.Graduated__c = TRUE, “Yes”, “No”)
2. User profile restriction:
Even the user do not have access to the parent object (ex. Candidate), the field value will still be displayed in the child object.
3. Updating the field in parent object:
The formula field in the child object will be updated automatically whenever there is change to the field in the parent object.