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
SFLLISFLLI 

Required readonly field

I am trying to create a required readonly field for a custom object.  Is it possible? Please advise,
Jeff TalbotJeff Talbot
At a simple level, you can't make a field read-only if it's required.... it doesn't make sense... the user wouldn't be able to save a record because they wouldn't be able to enter data in the required field.
 
I doubt you overlooked that, so I'm guessing that there is more to your request than what you've outlined. If you can give us more information, someone here might have some suggestions for you. Good luck.
IntegrationsIntegrations

I have a similar question....

On Contact the First Name, Last Name are required fields.  When they enter a new contact we require the name information.....groovy.  On an edit, however, we would like to make those fields read only as we have a seperate S-Control button defined for requesting a name change.  Is there any way to do this??

In the reading I've done it doesn't appear that there is, but thought I'd check out here as well.

Thanks, Tammy

Jeff TalbotJeff Talbot
Integrations:
 
You could implement a validation rule using the ISCHANGED fuction (this wouldn't make the field "read-only", but it would prevent a record from being saved with name changes and present the user with your custom error message directing them to your change-name s-control)
 
OR
 
You could have workflow change the record type after a Save, and setup a separate page layout for this record type where the name fields are read only -- the fields would truly be read only on this page layout but you'd have a disadvantage of having to remember to make future page layout changes in two places.
WhyserWhyser

Here's a validation formula you can use to implement this rule

If( ISCHANGED( field_name ),
If ( ISPICKVAL( PRIORVALUE( field_name ), "" ), false, true),
If (ISPICKVAL( field_name , "" ), true, false ) )

Bascially what the formula is saying is

If the field has changed, if the value for it before was blank, return no error (allowing you to change the value if it was blank before), otherwise return an error (not allowed to change its current value)

If the field has NOT changed, and the value for it is STILL blank, return an error (forcing the field to be required), otherwise return no error (meaning the value is staying the same).