function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
carlsosgcarlsosg 

How to show that a dynamic field is required?

The validation rules on our Leads object have gotten fairly complex. Users are complaining that they cannot easily see which fields are required before clicking "save".

 

In our process - when a specific Lead Status is selected, there are about 20 fields that become required (through validation rule). Is it possible via APEX to refresh a standard page layout - displaying the red bar next to dynamically required fields?

sfdcfoxsfdcfox

Apex Code only runs when invoked on the server. As such, it can't do things like dynamically refreshing the page, etc. Visualforce can do this, however, but you would have to be willing to rewrite the entire lead edit page, which may or may not be a trivial issue. In the absence of full Metadata API access (such as page layouts, record type assignments, and so on), if you have anything more complex than a simple layout, it may not be easily maintainable to go with a Visualforce route either.

 

What you CAN do is to use standard functionality (when possible). If you create picklist values, and you then make those required on the page layout, then, finally create dependencies on those picklists to the status field (i.e. when the Status is a certain value, the other picklists will have available picklist values). This runs dynamically without any custom coding at all. The only downside is that they must be picklist fields, and not text fields or any other type of field.

 

Personally, I would just create a bunch of picklists (if you have not yet reached your limit), and follow that pattern, then place the desired field to the right in a two column layout. This would at least provide a visual cue to the users to fill out those other fields. It might look like this:

 

Status: [ Open           ▼ ]

Reminder: [ -- None -- ▼ ]   Text Field:  [               ]

 

 

Status: [ Contacted   ▼ ]

*Reminder: [ Complete Text Field  ▼ ]   Text Field:  [               ]

 

(* would show required bar)

 

This gives you the general effect you're looking for without the mess of mass coding.

 

I know this isn't a perfectly ideal configuration, but it beats a ton of work for nothing.

carlsosgcarlsosg

Thank you for the response. The one problem with dependent picklists - is that it makes it impossible to put anything in the dependent fields, until the triggering Lead Status value is selected.

 

Our data entry process isn't linear enough for this to work.

sfdcfoxsfdcfox

The dependent picklists is only to remind the users to fill out the text field. The text field itself will still be editable even before it is required. The only thing we're doing is adding some eye candy so that the user receives a visual cue that they need to fill out additional fields.