Quick walkthrough showing how to use the Data Table screen component and Flow Filter actions to assign Facilities to a Lead without code. Includes architecture, step-by-step Flow design, and tips to avoid duplicate facility assignments.
Overview
This guide explains how to build a Screen Flow for assigning Facilities (a child of Hospital Account) to a Lead using the Flow Data Table screen component and list filters — no Apex or LWC required. It’s ideal for Intake users who receive patient referrals and need to avoid duplicate facility assignments.
Salesforce objects used
- Lead — stores patient information (flow launched from Lead record)
- Account — hospital account (Lead has lookup to referring Account)
- Facility — facility information (child records of Account via mapping)
- Hospital Facility Mapping — junction object linking Account and Facility
- Opportunity — used to store which Facility a Lead has been referred to (junction between Lead and Facility)
Flow design (step-by-step)
Build a record-triggered or quick-action launched Screen Flow on Lead. Key flow elements:
1. Get Opportunity Record Type
Use a Get Records to fetch the Opportunity RecordTypeId you will use when creating opportunity referral records. Store the recordTypeId in a variable.
2. Get Hospital Account Id from Lead
Use Get Records (or the record input) to fetch the Lead and read the referring Hospital Account lookup. When the flow is launched from the Lead record, recordId contains the Lead Id.
3. Get Hospital Mapping Records
Get Records to query all Hospital Facility Mapping records (or Facility child records) where Account = referring Hospital Account. This returns the list of potential Facilities to present to the user.
4. Screen — Data Table to Select Facilities
Add a Screen element and include the Data Table component. Configure the Source Collection to the list returned in step 3 so users can see and select one or multiple Facilities to assign.
5. Loop through Selected Mappings
Loop over the selected Facility records (or the mapping records). For each item:
- Use an Assignment element to populate an Opportunity record variable with fields: LeadId (WhoId or custom lookup), AccountId (Hospital), FacilityId (custom lookup), RecordTypeId, StageName, CloseDate (use today + 1), and any other required fields.
- Use another Assignment to add that Opportunity record variable to a List variable (collection) for bulk create.
6. Get Opportunities for this Lead
Use Get Records to fetch existing Opportunity referral records related to the same Lead. This helps prevent creating duplicates.
7. Decision: Any existing Opportunities?
If no existing opportunities, use Create Records to insert the whole list from step 5. If opportunities exist, proceed to filtering.
8. Filter the new list against existing referrals
Loop through the list you built and use the Flow Filter element (or use Collection Filter) to remove items where the FacilityId already exists in the existing opportunities list. Store the filtered results into a new collection variable.
9. Null-check and create filtered opportunities
Check if the filtered collection is empty. If not empty, use Create Records to insert the filtered collection. If empty, show a Screen telling the user no new facilities to add.
10. Error handling
Add a final Error Screen element to present any DML or unexpected errors. Consider fault paths on Get/Create elements to capture and display problems.
Best practices and tips
- Use collection variables and bulk Create Records to avoid DML governor limits.
- Use RecordTypeId and required fields during assignment to prevent insert failures.
- Prefer Collection Filter or the newer Filter component to compare facility Ids rather than nested loops when possible — simpler and more performant.
- Add meaningful user messages on the Screen (e.g., “3 facilities selected; 2 were already referred; 1 new referral created”).
- Use fault paths on Get/Create elements to show a friendly Error Screen rather than letting the flow fail silently.
When to use this approach
This no-code Screen Flow approach is suitable when:
- You need quick admin-level automation without Apex/LWC.
- You want a user-facing UI to select multiple related records (Data Table).
- Business logic is simple enough to handle with collection filters and assignments.
Conclusion
Using the Data Table screen component combined with Flow collection filtering gives admins a powerful, no-code way to present facility choices and avoid duplicate referrals. It keeps logic declarative, is easier to maintain than custom code, and provides a straightforward UX for Intake users.
Why this matters: For Salesforce admins and developers, this pattern reduces maintenance overhead, avoids unnecessary Apex, and ensures referral assignments are accurate — improving patient intake workflows and reducing duplicate work for staff.
Leave a Reply