How To

Highlight Open Cases on the Contact Record [Lightning Experience]


This is the last of four separate posts that will cover each record attribute shown on the flow screen on the Contact record.

Previous blog posts:

Here are a few lessons learned from implementing this use case:

  • Learn how to use flow to lookup and display data via an embedded flow component on a Lightning record page.
  • Provide descriptions, where provided, in Salesforce. This may be tedious step, I know, but your future self will thank you when you are trying to remember what you configured or assist other/future admins when troubleshooting or enhancing what was built. This includes variables, the purpose of a flow, what each flow element does, etc.

Business Use Case:  Addison Dogster is the system administrator at Universal Containers. Steven Moon is the Director of Sales. He wants his sales reps and support staff to know what cases are currently still outstanding for the Contact. Currently, reps and support staff will not know unless they look at the list of associated cases and review the status of each.

Solution: Being the #AwesomeAdmin that Addison is, she was able to solution this creatively using flow screens and embedding the flow component on the Lightning Contact page to highlight open cases in its own panel.



There is one limitation worth mentioning here. You will need to refresh the Contact record page if you make any changes to the open case list, such as added a new case or closed a case.

However, based on this Twitter thread, this may be something that Salesforce delivers in a future release. #ForwardLookingStatement


I think, for now, the need to page refresh isn’t a big deal since if you just updated the record or created or closed a case from the Contact record, you don’t really need to see that the Additional Contact Details section updated. It will update for the next person visiting the Contact record.

However, if you need flows to automatically refresh upon update, fellow MVP Doug Ayers created a workaround with a lightning component and VF page. Thanks, Doug!

Taking a look back at the consolidated flow, the highlighted boxes are the ones that pertain to this implementation only, along with the GenericSendEmailOnFault subflow.


Quick Steps:

1. Let’s create a visual workflow to lookup the Contact’s Account ID, then look up the Account Contact Roles with the Account ID and Contact ID. If an account contact role record is found, take the value from the IsPrimary field and populate the variable varContactIsPrimary. Then, display the variable’s value on screen.


In Lightning Experience, it is found under Process Automation | Flows.

A. Let’s create our flow resources upfront.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this decision is used for.

We need a constant to hold a line break html syntax. This is so that each open case listing will appear on its own line.


This variable will store the contact Id that is passed from the flow. Note: for embedded flows, the record Id is passed with this exact variable name, “recordID.” Note: The input/output type needs to be Input Only for the flow to work when called from the flow component.


This variable holds the count of the open cases associated for the Contact.


This variable stores the case number for each open case in the loop.


This variable holds each individual case’s case subject from the fast lookup for display on the open case list.


This sobject collection variable will store the case records retrieved in the case fast lookup.


This sobject variable holds the data for the case in the loop.


This variable holds the case information to display in the open case list.


This is a text template resource specifies the case information that we will show in the open case list. Here, we will display the <case number> | <case subject> with a line break.

<a href=”/one/{!sObjLoopCaseRecord.Id}/view”>{!varCaseNumber}</a> | {!varCaseSubject}{!lineBreak}


B. Let’s perform a lookup using the Fast Lookup flow element on the Cases object for all the cases where the ContactID is the value passed from the flow component into the recordID variable and the case status is not closed (i.e. cases are open). We will store this in the sobject collection variable and we will specifically save the case ID, subject and number.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this fast lookup is used for.


C. Now, we need to determine whether any open cases were found using a Decision flow element. It is important that we do this check. If no cases are found and we continue on with our process of taking the records in a loop as if there were records, the flow will fault. By doing this check and only allowing the flow to continue if there is at least one case, this will present flow faults. Who wants those?

For the Case(s) Found outcome, we will look at the sobject collection variable sObjCollectionCases is null false. This means there is at least one record.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this decision is used for.


D. Now that we have our list of open cases, we need to iterate through each record. So, we need a Loop flow element. This will take the records in the sObject Collection Variable sObjCollectionCases in ascending order and then work with each record in the sObject variable sObjLoopCaseRecord.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this loop flow element is used for.


E. Once we are inside the loop, we are going to use the record lookup using the Id in our sObject variable sObjLoopCaseRecord for the caseID to pull the case number and case subject for the open case list.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this record lookup flow element is used for.


F. Now, we will make two assignments via an assignment flow element. We need to add the formatted<case number> | <case subject> and line break to the accumulating case list (variable varCaseLookupResultsRow) and we will also increment the open case count by 1 with each loop case record.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this assignment flow element is used for.


Once we are done with the assignment for each record in the loop, we will end the loop.

G. Once we are out of the loop or there were no cases in the fast lookup, we will go to a Decision flow element. This will determine which screen to show on the Contact record page.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this decision flow element is used for.

For the outcome Has Cases, we will look at the variable varOpenCasesCount is greater than equal to 1.

The default outcome is No Cases.


H. Next, we will create a Screen flow element to show the list of open cases or show a message that there are no associated open cases.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this screen is used for.

Ensure that under Navigation Options, that you select the option “Don’t show Finish button.” and uncheck the “Show Pause button.”

Then, tab to the Add a Field tab, find the display text field and drag two to the screen area on the right. Then double-click on the display text field and configure it to match the screen below. Repeat for the second display text field.


I. Add the subflow Send Flow Fault Email. For instructions on how to create this, go to Step 2 of blog post: Maximize Maintainability With Process Builder and Componentized Visual Workflow.


J. Set your flow starting point. And connect the flow elements and the fault connectors to match the below…


K. Save as and provide the following properties.

Best practice tip: Provide a description so you and other/future admins know what this flow element is used for.


L. Click the “Close” button.

M. On the flows screen, activate the flow.


3. Finally, we need to add the flow component to the Lightning Contact record page. Find the Flow component under the Standard components and drag it to the desired location on the Contact record page. Then, select your flow and check the box that you want to pass the recordID into the flow.


Congrats, you made it to the end! You’ve implemented a flow that takes the Contact’s related cases and shows them on the Contact record.

Now, before you deploy the changes to Production, don’t forget to test your configuration changes.

  1. In Lightning Experience, navigate to a Contact record. Create at least one open case and at least one closed case.
  2. Refresh the Contact page. Verify that the Additional Contact Details panel shows the correct number of open cases and case information.
  3. Close a case. Refresh the Contact page. Verify the closed case information is removed from the panel.

Deployment Notes/Tips:

  • The flow and lightning record page can be deployed to Production in a change set (or can be deployed using a tool such as Dreamfactory’s Snapshot).
  • You will find the flow component in a change set under the Flow Definition component type.
  • You will need to confirm that all the configuration of a lightning record page change set deployed as expected.
  • Activate the flow as they are deployed as inactive in Production.