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
Anusha VankayalapatiAnusha Vankayalapati 

How to make a text field editable when a date is changed

Hi Team,

I have two fields Reason(Text field) and Approved date field on Quote Line object. The Reason field is made Read-Only on page layout. I have a requirement where in the Reason field should ONLY become Editable whenever the Approved date field is changed. Could you please help me in this.

Thanks.
Abhishek BansalAbhishek Bansal
Hi Anusha,

There are two options to acheive this:
  1. Remove the Read Only check from this text field and create a validation rule to make sure that this field is only changed when your date field is changed.
  2. If you want to keeo it read only than you have to create a new VF page for this. Override the New/Edit page with this VF paage and make the field editable based on the change in date field.
It is not possible in the standard layout to make a field read only or editable based on some conditins. Let me know if you need any further help on this.

Thanks,
Abhishek Bansal.
Anusha VankayalapatiAnusha Vankayalapati
Hi @Abhishek,

Could you help me with the first option. How can I make a text field editable when the date field is changed?
gaurav gupta 253gaurav gupta 253
Hi Anusha

In option 1 remove read only from page layout and then add validation. OOTB layout doesnt allow you to make field readonly or editable dynamically.

 
Abhishek BansalAbhishek Bansal
Hi Anusha,

As per the option 1, you need to remove the Read Only check from the Text field and create a validation like this:
AND(
NOT(ISCHANGED(Approved_Date__c)),
ISCHANGED(Reason__c)
)
This validation rule will make sure that the Reason field will only be changed when the Date field is changed. You can also adjust this validation rule if you want to add more conditions.

NOTE: Please take care of the API name of the fields in the validation rule.

Thanks,
Abhishek Bansal.
Anusha VankayalapatiAnusha Vankayalapati
Hi Abhishek,

Thnaks for all your quick responses. I have one more doubt on this. Cant we have trigger for this? Could you help with this.
Abhishek BansalAbhishek Bansal
Yes we can write triggers but why do you need that?
It can be simply achieved with validation rule.

If you still want to go with triggers than please create a trigger on before update and check the conditions same as mentioned in the validation rule.
If the conditions are satisfied just use .addError method to stop the update.

Thanks,
Abhishek Bansal.
Anusha VankayalapatiAnusha Vankayalapati
Hi Abhishek,

The requirement is like field should be read only on page layout as well as on FLS. But it should become editable when only date field changes. So, I thought Validation rule would not work. Could you please let me know how can we write a trigger logic for this? Your response would be helpful for me. 

 
Anusha VankayalapatiAnusha Vankayalapati
I am new to Salesforce Development. So could you please help me in writing the trigger logic
Abhishek BansalAbhishek Bansal
Hi Anusha, 

You can take help from the below link:
https://trailhead.salesforce.com/content/learn/modules/apex_triggers/apex_triggers_intro

Once you have something ready, I can help you in modifying the code to make it work as per your requirement.

Thanks,
Abhishek Bansal.