Can a Flow that is triggered by a Status change on a Case be made to pull all the data from a specified picklist or text field on all the Cases attached to that Case's Account, and then deposit that full text string into a specified 'collector' field on the Account record?
This is our Use Case:
We use Cases as assets, not as work orders; each Case represents a product installation.
Case 1 is for Product A and is in status 'In Progress'
Case 2 is for Product B and is in status 'Cancelled'
Case 3 is for Product C and is in status 'Stalled'
We need our Account record to contain a field that shows the full list of products in use (any status except Cancelled), pulled from the product field on each Case that is not cancelled.
My Flow needs to be triggered by a Case being changed to cancelled, or by a new Case being created, when it would gather a new list by pulling all the product fields from all the Cases still open under that Account. It's essentially a roll-up function.
What I cannot figure out is how to reference the parent account, I am guessing I have to define a variable that holds the Account ID of the Case that has triggered the Flow, but I cannot figure out how to do that. Are there any detailed examples of such a build I can consult or does anyone have time to hand-hold me through an example?
5 answers
Hi Kel,
You can do this by getting the cases related to the account that your case is related to, then looping through these cases and adding the text you want to a variable, then updating a field on the account with the data in the variable.A few considerations that are limitations of flow:
- You cannot use the ISCHANGED() function in flow, which means that you can't limit when the flow runs. I would want to limit it to only run if the status or product fields are changed to ensure optimized automation. You can either launch the flow through a process and use ISCHANGED() there or follow this unofficial way to use ischanged in before save flows (https://goravseth.com/ischanged-and-priorvalue-in-before-save-flows" target="_blank).
- You cannot insert a line break into a flow formula, so I can't display the text in the field in separate lines. There is an idea for thi (https://trailblazer.salesforce.com/apex/ideaView?id=0873A000000lIxrQAE" target="_blank)s.
Now to the flow:- I created this flow as a record-triggered flow, so it might be different if you create it as an auto-launched flow (passing variables, for example).
- Trigger the flow when: A record is created or updated
- Run the Flow: After the record is saved (though it could be before-save too)
- First, get the related cases to the account using a get record element.
- Set filter conditions to be AccountId --> Equals --> {!$Record.Account.Id}
- Store all records
- Choose fields and let Salesforce do the rest and store: ID, Status, Product__c, CaseNumber, and Subject
- Set a loop element for the get element (collection variable) you just used.
- Use collection variable {!Get_Cases_Related_to_Account}
- Create an assignment for a new variable adding a formula
- Variable:
- Simple text variable
- Data type = Text
- Formula:
- Formula using merge fields from fields from the case being looped
- Make sure to use the same formula syntax as with other formulas
"Case "&{!Loop_Through_Cases.CaseNumber}&" is for "&TEXT({!Loop_Through_Cases.Product__c})&" and is in status "&TEXT({!Loop_Through_Cases.Status})&". | "
- Outside of the loop, create an update records element.
- Make sure the object is account
- Filter is ID --> Equals --> {!$Record.Account.Id}
- Set field values for the account records equals Custom_Field__c (I used description) <-- Variable from earlier (Var_Case_Information_For_Account)
That's it! Make sure to save and activate your flow. Then test it in the sandbox!
Note: If you don't add a condition for ISCHANGED or launch it from a process using ISCHANGED, then the flow will fire on every creation or update of a case record. This is not optimal, please add a condition.
If this answer helped you out, please select it as best answer.