How To

Highlight Open Opportunities on the Contact Record [Lightning Experience]

FeatureOpps

This is the third of the 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 opportunities are currently still open for the Contact. Currently, reps cannot easily identify this information when reviewing the opportunity related list and reviewing the stage 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 opportunities in its own panel.

Account-OppsPointOut.GIF

AdditonalContactDetails-Opps

View image full screen

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

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

TwitterFlowRefresh.GIF

I think, for now, the need to page refresh isn’t a big deal since if you just updated the record, created or closed an opportunity 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.

AdditonalContactDetails-Flow-OpenOpps.GIF

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.

AdditonalContactDetails-Flow-Opps-Revised.GIF

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.

ConstantlineBreak.GIF

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.

recordID.GIF

This variable holds the count of the open opportunities for which the Contact has an opportunity contact role for.

varOpenOppCount.GIF

This variable holds the opportunity ID.

varOppID.GIF

This variable stores the opportunity’s name for display in the open opportunity list.

varOppName.GIF

This variable stores the opportunity’s stage for display in the open opportunity list.

varOppStage.GIF

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

sObjLoopOppRecord.GIF

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

sObjCollectionofOpportunities.GIF

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

varOppLookupResultsRow.GIF

This is a text template resource specifies the opportunity information that we will show in the open opportunities list. Here, we will display the <opportunity name> | <opportunity stage> with a line break.

tt_OppResults.GIF

B. Let’s perform a lookup using the Fast Lookup flow element on the OpportunityContactRole object for all the opportunities where the ContactID is the value passed from the flow component into the recordID variable. We will store this in the sobject collection variable and we will specifically save the opportunity ID.

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

AdditonalContactDetails-Opps-FastLookup.gif

C. Now, we need to determine whether any opportunities were found using a Decision flow element. It is important that we do this check. If no opportunities 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 opportunity, this will present flow faults. Who wants those?

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

The default outcome is No Opps Found.

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

AdditonalContactDetails-Opps-Decision1.gif

D. Now that we have our list of opportunities, we need to iterate through each record and find the open opportunities (i.e. Stage is not Closed Won or Closed Lost). So, we need a Loop flow element. This will take the records in the sObject Collection Variable sObjCollectionOpportunites in ascending order and then work with each record in the sObject variable sObjLoopOppRecord.

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.

AdditonalContactDetails-Opps-Loop.gif

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 opportunityID to pull the opportunity name and stage for the open opportunities 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.

AdditonalContactDetails-Opps-RecordLookup.gif

F. We need to make another decision based on the record lookup flow step. Here, we need to determine the outcome of Open Opp: whether the opportunity is open where the variable varOppStage does not equal Closed Won AND Closed Lost, or Opp Closed (default outcome).

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.

AdditonalContactDetails-Opps-Decision2.gif

G. Now, we will make two assignments via an assignment flow element. We need to add the formatted  <opportunity name> | <opportunity stage> and line break to the accumulating opportunity list (variable varOppLookupResultsRow) and we will also increment the open opportunity 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.

AdditonalContactDetails-Opps-Assignment.gif

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

H. 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 sObject variable collection sObjCollectionAdditonalContactDetails-DecisionOpps1.gifCases and ensure that it is not blank (i.e. is null false).

For the outcome No Opp, we will look at the variable varOpenOppCount = 0.

For the outcome Has Opps, the variable varOpenOppCount is greater than or equal to 1.

AdditonalContactDetails-DecisionOpps1.gif

AdditonalContactDetails-Opps-HasOpps.gif

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

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.

AdditonalContactDetails-Opps-Screen.gif

View image full screen

J. 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.

AdditonalContactDetails-Flow-Opps-Subflow.GIF

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

AdditonalContactDetails-Flow-Opps-Subflow1.GIF

L. 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.

AdditonalContactDetails-Flow-Opps-Properties.GIF

M. Click the “Close” button.

N. On the flows screen, activate the flow.

AdditonalContactDetails-Flow-Opps-Activate.GIF

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.

AdditonalContactDetails-Opps-LightningAppBuilder.gif

View image full screen

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

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

  1. Create at least one open opportunity and at least one closed opportunity and add a contact as an opportunity role.
  2. Refresh the Contact page. Verify that the Additional Contact Details panel shows the correct number of open opportunities and opportunity information.
  3. Close an opportunity (i.e. stage = closed won or closed lost). Refresh the Contact page. Verify the “closed” opportunity 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.

 

4 thoughts on “Highlight Open Opportunities on the Contact Record [Lightning Experience]

  1. Jen, I follow as a non-admin biz analyst because I like the idea of having Salesforce do as much as possible for my sales users and you provide some really interesting use cases. But I’d love to see a before and after image of what your automations provide the ultimate user. The ending GIF on this post, as an example, is too small of an image to be able to see any sort of detail about what your process provides as a user experience. Just a suggestion. SD

    Like

Comments are closed.