back to blog
Add Visibility to Related List
July 12 2022 • 25 min read

BUSINESS CHALLENGE

Visibility can be set for components in lightning pages based on criteria. By default the lightning pages use Related Lists component to display the related objects records.

What if you want to display records of a specific object based on criteria in the related list. The Related Lists is a single component. Visibility cannot be set for individual related object’s records.

To overcome this, we can use a Related List - Single component for each individual related object's records and then visibility criteria can be set. 

featuredimage

WHAT IS “RELATED LISTS”

Related Lists is a standard component that displays records with a lookup or master-detail relationship to another record, like a section of a record detail page that lists all the items related to that record.

vrls 1

WHAT IS “RELATED LIST - SINGLE”

The Related List - Single component shows a list of related records based on one specific object. For the Contact detail page, you can specify to see the cases related to that Contact, without seeing all other types of related records.

vrls 2

WHY DO WE NEED A RELATED LIST - SINGLE COMPONENT?

What if you want to show Approval History information only for the opportunity owner. In case of Related Lists, one component displays all the related records information. Visibility can only be set for each individual component.

In order to solve the problem, we can use multiple Related List - Single components for each related Object’s records and then set the visibility for specific component.

STEPS TO ACHIEVE THE REQUIREMENT

  1. Create a Custom Field ( to control component visibility )
  2. Add the Related List - Single component to lightning record page

CREATE CUSTOM FIELD 

  1. Click Gear Icon → Click Setup.

    vrls 3

  2. Select Object Manager → In the Quick find search and Select Opportunity.

  3. Select Fields and Relationships → Click New.

    vrls 4

  4. Select Formula as data type → Click Next.

  5. Enter Approval History Visibility as Label → API Name will be Automatically Populated. Here we named the field as Approval History Visibility because we are going to control the visibility for Approval History. It can be named as per the requirement.

  6. Select Check Box as the Formula Return Type.

    vrls 5

  7. Click Next.

  8. Enter the below mentioned formula. This formula updates the fields Checkbox value to Checked if the user who is viewing the record is the Opportunity Owner, else it updates the field value to Unchecked

    “ IF($User.Id = Owner.Id, True, False)” 

    vrls 6

  9. Click Next.

  10. Check the Visibility for required Profiles. For the Profiles which need only read access check both Visible and Read Only.

    vrls 7

  11. Click Next.

  12. This field is created only to control the visibility for the Related List - Single component and this field is not required on the page layout → Uncheck the Add Field checkbox and Click Save.

    vrls 8

NOTE

Here a custom field is created in order to determine if the user viewing the record is the Opportunity owner, so that we can control the visibility of the component.

ADD RELATED LIST - SINGLE TO LIGHTNING RECORD PAGE

  1. Select any opportunity record → Click Gear Icon at the top of the page.

  2. Click Edit Page.

    vrls 9

  3. On the left pane we have all the available components, drag and drop the Related List - Single standard component onto the page to a required position.

  4. On the right pane select Use this Opportunity for Parent Record option, For Related list option choose the object whose records should be displayed in the component. Here we choose Approval History. For the Related List Type option choose as per requirement.

    vrls 11

    vrls 12

Please refer to the below images with related contacts for an Opportunity, for the related list types.

vrls 13

In Enhanced Related List Type, You can control the number of rows visibility in the right pane.

vrls 14

  1. Make sure that the component you want to set the visibility, is selected and Scroll down to the bottom on the right pane, Click Add Filter under Set Component Visibility.

    vrls 15

  2. Select the field Approval History Visibility as Field, Equal as Operator and True as Value.

    vrls 16

  3. Click Save and go back to the record page.

    vrls 17

  4. If the user viewing the record is the Opportunity Owner, the Approval History will be visible in the related list. 

    vrls 18

  5. If the Owner has been changed to any user other than the Opportunity Owner, the Approval History will not be visible in the Related List.

    vrls 19

WRAPPING IT UP

In this Blog we explained about the types of Related List components and a way to control component visibility using a custom field.

Leave a Comment

Your email address will not be published

© 2024 Digital Biz Tech