how to fetch related records using Salesforce Flows

How to fetch Related Records using Salesforce Flows

In this blog we will provide step-by-step insights into how you can fetch related records using Salesforce flows enhancing user experience and boosting productivity.

In the ever-changing world of Salesforce, where data is key, being able to effortlessly display related records makes a huge difference.

Whether working with standard objects like Opportunities and Contacts or diving into the depths of custom objects tailored to your unique business needs, the key to unlocking a more comprehensive view lies in mastering Salesforce Flows.

Business Scenario: Fetch related Contacts and Opportunity records for account object using Salesforce flows

Configure Screen flow:

Create a new Resource: Create a ‘Variable’ resource with data type ‘Record’ with Object ‘Account’. Make this variable ‘AccountRecord’ available for input.

To check how the flow works save the flow, ‘Fetch Related Records’ and click on debug. In the input variables, we can see all the Account Records are available to send the data to the flow.

Get Record Element: An Account ID is used to get a particular account’s related contacts. Therefore condition is field ‘AccountId’ equals ‘{AccountRecord.Id}’ where AccountRecord is the variable. We have to store all the records.


Add Screen Element: Drag and drop the Data Table from the components on the canvas. Click on the Data Table and enter the details such as API Name ‘Related_Contacts_Data_Table’.

The Source Collection is ‘Contacts from Related Contacts’ and configure rows as ‘View Only’. Display Name and Email using the configure column option.

Debug the flow and select any Account. hence, the screen flows display all the related contacts and respective Emails in tabular form.

To Display Related Opportunities: Add a Get Record element before the screen element and select the object ‘Opportunity’. The API name for Account on Opportunity object is ‘AccountId’ so the condition is ‘AccountId’ equals {AccountRecord.Id}.

Now click on the screen element, and drag and drop the Data Table. Select Source Collection ‘{!Related_Opportunities}’; the row selection mode is ‘View only’.In the configure columns add the Opportunity name and Stage to display.

Supercharge your certification prep with our Salesforce Certification mock exams series.


Save the flow and debug. Hence the flow displays related contacts and opportunities in tabular form with required fields.

Custom Object:

Create a ‘Project’ custom object and relate it with the Opportunity object with a Master-Detail relationship.



Create a new ‘Screen Flow’. Firstly add a new resource with a resource type as ‘Variable’ with Data Type ‘Record’ and make it available for input.


In order to fetch the related projects add a Get record element and select the object as ‘Project__c’. To filter the Project Records set the condition as ‘Opportunity__c’ equals ‘{!OppRecord.Id}’



To display related Opportunities use Screen Element. Use Data Table and Source Collection as related projects. Configure columns as ‘Project Name’ and ‘End Date’



Save and Debug the flow to show all the related projects to a particular opportunity.


1. What are Screen Components in Screen Flow?

Screen components come in various types, categorized broadly into three groups. “Display Components” solely present information and do not interactively engage with user input. On the other hand, “Input Components” actively collect input from users, retaining that information for subsequent use within the flow.

Additionally, “Record Fields” function similarly by receiving input from users, but instead of holding it within the flow, they store the input in a record variable.

2. How does the External Lookup relationship work in Salesforce?

External Lookup relationships link a Salesforce object to an external object in an external data source, allowing you to reference and use data from external systems.

3. How are relationships maintained during data imports and exports?

Relationships are maintained through record IDs. During data imports, you must ensure that related records have the correct IDs and that data exports include related records as needed.

For more information, Check out the video below!!

Get a complete Roadmap To Learn Salesforce Admin And Development

Share Now

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *