Validating unique_name field across all Opportunity records for Opportunity name field on a Screen flow - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
John SellersJohn Sellers 

Validating unique_name field across all Opportunity records for Opportunity name field on a Screen flow

Current scenario in place for a custom clone of Opportunities
We are  using a screen element flow(in conjunction with a Lightning component) to allow our users to peforme a custom clone of an Opportunity (only specific fields) in Lightning. 
We use a unique name field on Opportunities via a workflow to make sure all of our Opportunities have unique names. 
Current problem frustrating users:
On the screen flow element page,  the user has an input field for Opportunity name.
I set a simple validation rule that ensures the name entered doesn't match the current Opportunity's name (source of the clone - compare to the variable captured in the flow lookup); however it doesn't query all 40k Opportunity unique name fields, so if they use a name that exists in the system, then no validation occurs to warn them. Instead the flow throws an ugly error with no context "Flow record couldn't be created" and they have to start over - not knowing that the issue is the Opportunity Name needs to be unique.
Solution idea/request for help from the community:
Looking for a method to display a relevant validation error that queries all unique name fields on Opportunities so they can get the error on the screen before clicking next.
Does anyone know a formula validation that would do such a thing?
Validation formula that could be created on the sceen element page that validates the Opportunity Name input field against all Opportunity record's unique_name__c field?
To ensure the name doesn't exist across all records in the system (this would improve Lighting user adoption for this feature so they don't have to start over if it fails). 

Thank you,
Best Answer chosen by John Sellers
Greg OwenGreg Owen
I don't think you're going to be able to throw the validation on the flow screen.... you would need something custom to do the search as they type or after they leave that input box. But you could add another lookup after they enter the name and if the name already exists then you could have another screen telling them the error and asking for a new name. Likely you'd want to create a loop so they can go around a few times :).

Why not just use a system generated autonumber or something? what's the name format and business case for the name to be unique?

All Answers

Greg OwenGreg Owen
I don't think you're going to be able to throw the validation on the flow screen.... you would need something custom to do the search as they type or after they leave that input box. But you could add another lookup after they enter the name and if the name already exists then you could have another screen telling them the error and asking for a new name. Likely you'd want to create a loop so they can go around a few times :).

Why not just use a system generated autonumber or something? what's the name format and business case for the name to be unique?
This was selected as the best answer
John SellersJohn Sellers
Thanks Greg.
Name format is based on many different elements depending on department, product, service, etc. and our finance department needs the names to be unique to avoid confusion with reporting. Autonumber wouldn't work since We report on name filters to help identify different areas of the business.

Thank you for the tip to use another screen and the loop feature. I will explore that. Loving the screen flow, but I need to enahnce my knowledge of the loop feature for certain.
Greg OwenGreg Owen
John you could also attempt to systemize value in the name field. For example you could lookup the users department and then in the flow ask them the additional question needed to form the name. Of course you'll still have to make sure it's unique...but you can remove the end user hassle of entering the name.