Friday, April 25, 2014

Salesforce: An Alternative to the Banner Visual Force Page

From time to time, there is a requirement to display a warning or a soft error on a Salesforce detail page that will alert the user before an action takes place.  For example, warn the user to complete certain fields before converting a lead.  This allows the user to save a lead with minimal information, but add to it over time until he can convert it.

One way to do this is to create a custom Visual Force page that displays as a banner on top of the detail page.  This page can be controlled by an APEX class that performs all the validations and displays a text depending on the information already on the lead.  It could say "Postal Code is required before converting this Lead."  And that message can be in red, and in a box.  It's great because you can control the look through coding.  The downside is, it's coding.

An old alternative was to use a standard Text field with IMAGE functions, displaying a red flag, yellow flag, or green flag, and an appropriate message.  This link details that solution.  This is a good no-coding solution. However, the text is just as big as regular fields, and can be missed.



If they miss this message, it is frustrating to the user, especially if it is preventing him from submitting for approval, and the only available message is the standard message that it does not meet any approval entry criteria.



It is very cryptic.

Some time in 2010, Salesforce released a new data type, Rich Text Area.  And instead of using a regular field for a warning message, this data type can be used.

First, create the field with an appropriate length, say 1024.  It should be read only to everyone, so that only workflow field updates will populate it.  Then add it to the top of the page layout in its own section.  The section heading can be removed, which is what I recommend so that it behaves like a visual force banner.






The field label cannot be hidden, so label it appropriately, like "Messages".

And now, you can use standard Workflow that fires appropriately based on certain criteria, and put a message in.  For example, if Country is US, CA, UK, and Postal Code is NULL, you can set the Messages field to something like:

"<p><strong><big><span style=\"font-size:26px;\"><span style=\"color:#ff0000;\">Postal Code is required for this country before converting.</span></span></big></strong></p>"


The above formula will be shown on the page like this:



This allows a user to still save the record, and he can come back and add the postal code later.  A little bit of HTML knowledge can come in handy here, but there are a handful of HTML generators online for those unfamiliar.  They may insert unnecessary tags, so the administrator may need to experiment and test to see what looks best.

Always keep in mind that there are limits on the number of workflows and limits on the formula editor.  This is where an admin can get creative to work around these limits.


No comments:

Post a Comment