Last Updated on February 10, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
Many of us are unaware of the power of Salesforce Flow (aka Lightning Flow). It allows you to minimize the code used in your organization by using flow. It’s a tool whereby drag and drop you can build an awesome screen without writing a single line of code. You can even insert, update, Delete a record in Salesforce, all you can do without writing code even Salesforce administrator can use flow very easily.
Business Use Case
Warren Mason, Gurukul on Cloud (GoC) awesome System Administrator, received the following requirement – business wants to update remaining opportunities to Closed lost except for the one whose stage is just updated to Closed won for the same account.
Automation Champion Approach (I-do):
While this can be solved using various automation tools like Apex, etc, we will use Screen Flow.
Before proceeding ahead, you have to understand how account and opportunity are connected. If an opportunity has AccountId populated means, it is connected to an account.
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it. Let’s begin building this automation process.
Guided Practice (We-do):
There are 2 steps to solve Corey’s business requirement using After-save Record-Triggered Flow. We must:
- Define flow properties for record-triggered flow
- Add an update records element to update related opportunity from the same account to lost
Step 1: Salesforce Flow – Define Flow Properties
As we have a requirement to update the child records (opportunities) of the parent account when an opportunity marked as closed-won. This is why we have to use the After-save flow on FeedItem.
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flow option and click on Next and configure the flow as follows:
- How do you want to start building: Freeform
- Trigger the Flow When: A record is created or Updated
- Run Flow: After the record is saved
- Object: Opportunity
- Select Any Condition Are Met (OR).
- Set Conditions
- Row 1
- Field: StageName
- Operator: Equals
- Value: Closed Won
- Click Add Condition
- Row 2
- Field: AccountId
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Row 1
- Click Done.
Step 2: Lightning Flow – Update Records – Update Opportunities from the Same Account to Closed Lost
The next step is to update the opportunities from the same account to closed lost. For this, we will use an Update Record element.
- Under Toolbox, select Element.
- Drag-and-drop Update Records element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Click Specify conditions to identify records, and set fields individually
- Object: Opportunity
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: IsClosed
- Operator: Equals
- Value: {!$GlobalConstant.False}
- Click Add Condition
- Row 2
- Field: Id
- Operator: Does Not Equal
- Value: {!$Record.Id}
- Click Add Condition
- Row 3
- Field: AccountId
- Operator: Does Not Equal
- Value: {!$Record.AccountId}
- Row 1:
- Set Field Values for the Opportunity Records
- Row 1:
- Field: StageName
- Value: Closed Lost
- Row 1:
- Click Done.
In the end, Warren’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 51
- Interview Label: Update Related Opportunities to Lost {!$Flow.CurrentDateTime}
- Click Save.
Proof of Concept
Now onwards, when a business user updates the Opportunity Stage to Closed Won, Salesforce Flow will automatically update the related Opportunities from the same account to Closed Lost.
- Currently, there are three Opportunities attached to Opportunity Deutsche Telekom Inc as shown in the following screenshot
- Now we update the Stage on Deutsche Telekom Inc – Q2 FY21 to Closed Won.
- Navigate back to the Account to confirm other records are changed.
Formative Assessment:
I want to hear from you!
What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes?
Make a post and tag me on Twitter @automationchamp, using #AutomationChampion.
Hi Rakesh,
I wonder why u did not use Before Save Update for the above given problem.? We are updating the same object record’ on which we have written our trigger.Is it because we are updating other opp records not the one which has caused the flow to fire.?
Because we’re updating related opportunities.
I am getting the following error when click the custom button on the Opportunity detail page
An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information.
Pls post your error log here
Is this what you are looking for?
WF_RULE_INVOCATION; WF_APPROVAL; WF_FIELD_UPDATE; WF_SPOOL_ACTION_BEGIN; WF_ACTION; WF_FORMULA; WF_RULE_EVAL_BEGIN; WF_RULE_EVAL_END; WF_RULE_EVAL_VALUE; WF_CRITERIA_BEGIN; WF_CRITERIA_END; WF_RULE_ENTRY_ORDER; WF_RULE_NOT_EVALUATED; WF_RULE_FILTER; WF_ESCALATION_RULE; WF_ESCALATION_ACTION; WF_TIME_TRIGGERS_BEGIN; WF_TIME_TRIGGER; WF_ACTIONS_END; WF_ENQUEUE_ACTIONS; WF_APPROVAL_SUBMIT; WF_APPROVAL_SUBMITTER; WF_APPROVAL_REMOVE; WF_NEXT_APPROVER; WF_EVAL_ENTRY_CRITERIA; WF_PROCESS_FOUND; WF_SOFT_REJECT; WF_HARD_REJECT; WF_PROCESS_NODE; WF_ASSIGN; WF_REASSIGN_RECORD; WF_RESPONSE_NOTIFY; WF_OUTBOUND_MSG; WF_ACTION_TASK; WF_EMAIL_ALERT; WF_EMAIL_SENT; SLA_PROCESS_CASE; SLA_NULL_START_DATE; SLA_EVAL_MILESTONE; SLA_END; WF_KNOWLEDGE_ACTION; WF_SEND_ACTION; WF_CHATTER_POST; WF_QUICK_CREATE; WF_FLOW_ACTION_BEGIN; WF_FLOW_ACTION_DETAIL; WF_FLOW_ACTION_END; WF_FLOW_ACTION_ERROR; WF_FLOW_ACTION_ERROR_DETAIL; WF_APEX_ACTION; EVENT_SERVICE_PUB_BEGIN; EVENT_SERVICE_PUB_END; EVENT_SERVICE_SUB_BEGIN; EVENT_SERVICE_SUB_END; FLOW_CREATE_INTERVIEW_BEGIN; FLOW_CREATE_INTERVIEW_END; FLOW_CREATE_INTERVIEW_ERROR; FLOW_START_INTERVIEWS_BEGIN; FLOW_START_INTERVIEWS_END; FLOW_START_INTERVIEWS_ERROR; FLOW_START_INTERVIEW_BEGIN; FLOW_START_INTERVIEW_END; FLOW_INTERVIEW_PAUSED; FLOW_INTERVIEW_RESUMED; FLOW_ELEMENT_BEGIN; FLOW_ELEMENT_END; FLOW_ELEMENT_FAULT; FLOW_ELEMENT_DEFERRED; FLOW_ELEMENT_ERROR; FLOW_BULK_ELEMENT_BEGIN; FLOW_BULK_ELEMENT_END; INVOCABLE_ACTION_ERROR;
Nope, look at the error message reason
Error element Update_all_Opportunity_as_Closed_Lost_except_Closed_Won (FlowRecordUpdate).
The flow tried to update these records: 0061I0000028E0JQAU. This error occurred: ALL_OR_NONE_OPERATION_ROLLED_BACK: . For details, see API Exceptions.—The flow tried to update these records: 0061I000005MixgQAC. This error occurred: ALL_OR_NONE_OPERATION_ROLLED_BACK: . For details, see API Exceptions.—The flow tried to update these records: null. This error occurred: REQUIRED_FIELD_MISSING: Required fields are missing: [Discount_Percent__c]. For details, see API Exceptions.
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Charu_s_Fow_for_updating_opportunity_to_Closed_lost
Type: Flow
Version: 2
Status: Active
Flow Interview Details
Interview Label: Charu’s Fow for updating opportunity to Closed lost 2/5/2018 9:58 AM
Current User: Charu Agarwal (0051I000000Q99y)
Start time: 2/5/2018 9:58 AM
Duration: 0 seconds
How the Interview Started
Charu Agarwal (0051I000000Q99y) started the flow interview.
RECORD QUERY: Account_id_of_closed_won_opportunity
Find one Opportunity record where:
StageName Equals Closed Won
Result
Successfully found record.
{!AccountId} = null
RECORD UPDATE: Update_all_Opportunity_as_Closed_Lost_except_Closed_Won
Find all Opportunity records where:
AccountId Equals {!AccountId} (null)
StageName Does not equal Closed Won
Update the records’ field values.
StageName = Closed Lost
Result
Failed to update records that meet the filter criteria.
I got it to work. Thank a lot for all you do. 🙂
🙂
Thanks for the detailed information. Can you please explain about Use Case 1 ( Popup )
Embed your Flow in a Visualforce page and then use JavaScript for pop-up.
Amazing Posts Rakesh.
I am hoping to get some solution on my requirement ,when Account owner is changed,defaultly,Opportunity owner changes too,but it doesn’t trigger Opp owner adding to the Opp team.I have been tried Process builder and Apex coding.but it couldn’t working on it ,is it possible with flows?
Thanks,
harish.
Been working on something similar but with no luck I am trying to update a Lead date/time field based on the last completed Task date/time. For some reason, I can not capture the Lead ID with the associated Task.
Please post the complete screenshot of your Flow
Did my image post ok?
No
Here you go. http://robrung.com/flow-process.jpg
Figured it out. I neglected to pass the vLeadID from my Process Builder that invokes the Flow action. Sometimes the most simple things that get overlooked cause the biggest headaches…
Glad to know 🙂
Hi Rakesh
Can you please explain how the account Id was populated? I didn’t see that it was passed using the custom button.
Thanks.
Please refer step 3
Hi Rakesh,
I tried the “Visual workflow game changer for Salesforce admin/developer” but did not work as expected.
dont know what I missed ? did it exactly as instructed. ?
is there any permissions etc I need to turn on.
Can you please post the screenshots ?