Lightning Layout Tricks: The Rich Text Validation Rule

Validation rules are a wonderful way to instill best practices, reinforce business processes, and help with keeping data entry consistent and clean.  They can also make integration, deployments, data loads, and user experiences miserable.

A well-meaning admin can grind the wheels of automation and integration to a halt by inserting a needed validation rule without looking at all the implications.  At the same time, users loath hitting save and seeing red error messages and pop-ups blocking them from completing their work.

Luckily with Lightning Components we can create proactive coaching experiences for users vs reactive validation rules, all with the help of conditional filtering.


Use Case

Universal Containers wants users to add products to opportunities before moving to the second stage of an opportunity.  They have a rollup summary field (Products__c) that counts the number of product records and a validation rule that prevents users from moving to Stage 2 if that field is less than 1.

However, reps edit their opportunities and enter a lot of information only to encounter a validation error that requires them to cancel their edit and go to the related lists tab, losing their work.

Sales leadership has asked you, the rockstar Salesforce Admin, to come up with a proactive solution to save time, effort, and frustration.  Luckily, you have just the trick with conditional rich text components!


The Build

  1. Create a field that captures your validation criteria – I say this because its sometimes easier to reference formula field, checkbox field, etc in conditional components then building out your validation logic in that window.  In our use case, we are simply using a rollup summary field that counts opportunity products.
  2. Add a Rich Text Component – add the component and enter the message you want to show users when the record will encounter a validation error based on record attributes.  Pro Tip – you can copy and paste gifs into rich text components. 
  3. Make your RT Component Conditional – use the component filter so your rich text component only appears when your field from #1 meets what would normally be your validation criteria.
  4. Drive the point home (optional) – sometimes users may need some extra prompting and we got a fix for them too.  For this use case, when a user insists on going to stage 2 without adding products, we hide all record tabs and display a single ‘Opportunity Product’ related list – prompting users to enter a product to continue with their opportunity.

Add Your Control Field – in this use case, we use a RUS that counts products

 

Add your Rich Text Component – Include your proactive message and maybe some flashing red lights for emphasis 🙂

 

 

Make your Rich Text Component conditional on your criteria field, so its only there when the record is not following the guidelines.

Annddd lastly…if you really want to enforce your rules, give them no other choice.  Make every other component conditional and use Quick Actions + Related Record Components or in this case a Related List – Single Component to only allow them to complete the edit you want.

Note my filter below – if they progress beyond Stage 1 and products are less than 1, they get this product list and nothing else!

That’s because all my other components are filtered to disappear when Products is less than 1 and Stage is greater than Stage 1!

 

Check it out in action – that senior sales rep thinks he can just skip your warning message? Nope, because you SHUT IT DOWN! Admin 2, Rep 0. 

 

Click to save the Flashing Red Light!

Comments

  1. Carlos Siqueira says:

    I love conditional components and was showing off at my Lightning Champions presentations since last August. In WI19 we get the option to make the conditional on Permission Sets, which adds another layer of flexibility.

    • Tom says:

      Me too! We came up with a client solution the other day in 5 minutes using conditional components that would have taken hours of code to resolve.

    • Tom says:

      You are right – think about how many page layouts, record types, visualforce pages, etc can be avoided with some creative component usage.

  2. Heidi says:

    Hi! I’m trying to setup a rich text field similar to yours with the flashing lights. Can you advise where you found those? All the ones I try are inserting too many characters into the field and it won’t save. Thanks!

  3. Sheena says:

    How exciting that we can copy and paste GIFs into SalesForce! Any recommendations where to find animated icons like the siren above?

Leave a Reply

Your email address will not be published. Required fields are marked *