[SalesForce] How to access child record IDs through lookup in a Flow

I'm working a scenario where the Address of a parent record once changed shall update the address field of the child records as well.

Initially i created a process to do so and it's working fine.

What i want is to leverage Flows to do the updation of child records. If i create a helper flow with a variable to hold the ID for the parent record. I'd then pass the ID from my process to the flow and shall be able to fetch the new address field through a lookup.

But i'm stuck with fetching the child record IDs. It's not apex so can't put a system.debug and i can't use screens to see debug messages, becuase in that case it won't be autolaunch flow and i wouldn't be able to pass the parent ID from my process.

I believe i'd need to loop through each ID once i have them and then update each record.

I had been googling it for a while but not sure how to move forward.

Using process builder solves this but i'm learning flows and understanding features like looping, updation, looups would really help in automating complex scenarios.

Best Regards,
Sangram

Best Answer

Ok, here's how I would do this. You're good with passing the ID into the Flow to get what the address should be.

  • Make a Record Lookup pointing to your source record to get your desired Address values pulled into various variables.
  • From there, you need to get a sObject Collection of all of the records that you want to change. Create a Fast Lookup for this, searching your target object for all records where the Parent Record is equal to the parent ID variable you passed in at the beginning.
  • In the Fast Lookup, set your Variable to an SObject Collection Variable. You'll want to also set your Fields at the very bottom to any Address fields you wish to possibly change.
  • Now create a Loop. Your loop should set to loop through the SOBject Collection Variable you just created, and the Loop variable should be a new SObject Variable. This tells the Flow that it needs to start going through every record you captured in the Collection, and the SObject Variable states/holds which record is currently being used by the Loop.
  • From your Loop, point to a new Assignment element. In your Assignment element, you can set the SObject Variable's address fields to the various values you got from your initial Record Lookup. You can set all of the fields in one Assignment.
  • You've actually completed the loop now. Draw an arrow back from your Assignment element to the Loop element.
  • Now make a Fast Update, telling it to update the SObject Collection Variable that contained all your records. Draw an arrow from your Loop element to the Fast Update, telling it to run when all records have been run in the Loop.

The Fast Lookup gets all the records and data that needs to be changed, the Loop passes each record to a handler, the Assignment changes the values in the handler, then goes back to the Loop to get a new record. It will repeat this until it runs out of records, then runs a Fast Update to push everything back up to the system. Slick, eh?