Loading

Salesforce Platform: Fetch Related Object Records Using Lightning Flows (No Code)

게시 일자: Apr 2, 2026
상세 설명

No Code Solution to fetch records between two related objects related using Junction Object with the help of Salesforce Lightning Flows

솔루션
  • In many business process scenarios, we have to fetch records between multiple objects and sometimes the objects are not directly related that is they don’t have a direct 1:1 relationship or 1:n relationship. In order to relate the data in cases of Many to Many relationships we use Junction. However fetching the related parent object record using the Junction object may be a conundrum
  • Let’s look at how we can use Lightning Flows to fetch the indirectly related Parent records efficiently. We are using an Auto launched flow which is mainly used to create a reusable piece of logic that can be used as per one’s need
  • A common business scenario that many would come across is trying to fetch related Opportunity Line Item records related to an Opportunity under an Account. In this scenario the Opportunity Object is acting as a Junction object between Account & Opportunity Line Item object

Step 1: Create a Autolaunched Flow

  • In the first step, we will create a Flow
  • Go to Setup, type Flows in the Quick find box
  • Click New Flow
  • Select Start From Scratch, Click Next
  • Select Autolaunched Flow type, and click Create

Step 2: Create a Variable of Resource Type Variable. Provide a relevant API Name to the variable, Description and Data type as Text or any Data type depending on your business use case

 

Step 3: We fetch all the related Opportunity Records under an Account using the Get Records element. Try to use filters or declare which field values under an Opportunity are relevant to the current context of the process

  • Create a Get Records element  and provide relevant Label, API Name,  Object, and Condition Requirements as shown the screenshot below 

Step 4: Create a Variable of Resource Type Variable. Provide a relevant API Name to the variable, Description and Data type as Text or any Data type depending on your business use case. Check the Allow multiple values (collection) checkbox

Note: Please be sure to  check the above checkbox, as the Flow would then treat the variable as a list/array instead of a simple variable

Step 5: Loop over the records that were retrieved from the previous Get Records element

  • Create a Loop element  and provide relevant Label, API Name,  Collection Variable as shown the screenshot below

Step 6: Use an Assignment element inside the loop to store the Opportunity Ids inside the newly created variable using the + operator. This step would append the related Opportunity Id of an Account into the list

  • Create a Assignment element  and provide relevant Label, API Name, and Set Variable Values as shown the screenshot below

Step 7: Use a Get Records element to fetch the related Opportunity records based on the Opportunity Ids in the list variable by using the IN operator. This would make sure that you only fetch related Opportunity Line Items which are related to the Opportunities under the Account

  • Create a Get Records element  and provide relevant Label, API Name,  Object, and Condition Requirements as shown the screenshot below 

  • By having the above logic present in your Salesforce Lightning flows you can retrieve records of objects which are related using Junction Objects

___________________________________________________________________________________________

Written by: Meghesh Shenoy | Forum Ambassdor


Meghesh Shenoy is a Salesforce developer, a Salesforce Forum & Mulesoft Ambassador. He is a Mulesoft and Salesforce Certified Developer, carrying the knowledge of building automation solutions using Salesforce and Mulesoft. Meghesh is passionate about sharing knowledge and experience and also helping others sharpen and grow their Mulesoft & Salesforce skills together.

 

Submissions reflect only the opinions of the user who made available the Submission and not the opinions of Salesforce, regardless of whether the user is affiliated with Salesforce, and may contain or constitute products, services, information, data, content and other materials made available by or on behalf of third parties ("Third Party Materials).  Salesforce neither controls nor endorses, nor is Salesforce responsible for, any Third  Party Materials, including their accuracy, validity, timeliness, completeness, reliability, integrity, quality, legality,  usefulness or safety, or any applicable intellectual property rights. Any Submissions made available through any message board or forum in response to posted questions, or that otherwise purports to answer any questions, including any questions about Salesforce or Programs, are made available for your general knowledge only and should never be relied upon as answers to your specific questions (even if an answer is marked as a “best” answer or with any similar qualifications). You should always contact Salesforce support for answers to your specific questions. Salesforce has no control over Submissions, and is not responsible for any use or misuse (including any distribution) by any third party of Submissions. 

 

If you have questions, tap into the wisdom of our entire Trailblazer Community here: https://trailhead.salesforce.com/trailblazer-community/feed

 

 

Knowledge 기사 번호

004810935

 
로드 중
Salesforce Help | Article