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
Hari.gsHari.gs 

Customize a date field's edit action

Hi all,

 

I have to cutomize a date field in Account Object. When a user tries to edit a date field, say Created Date, I need to check whether a value already exists in that filed, if exists I should not save the new value or should not allow the user to edit the field. If the value is empty I should be able to edit it save the new value. Using a trigger I can do this while editing and saving a Account Object. But from UI if a user performs edit how can I perform this check? Please help.

 

Thanks and Regards

Hari G S

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Yes but you cannot do that while using standard account layout. You cannot give any condition for any field in the standard page layout. You can only make that field Read Only through layout. But you can't give any condition there like if it is not null there read only like this. It will become read only for all.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

All Answers

souvik9086souvik9086

In the client side you can do like that

 

 

<apex:page standardController="Account">
<apex:form >
<apex:outputField value="{!Account.TestDate__c}" rendered="{!Account.TestDate__c != NULL}"/>
<apex:inputField value="{!Account.TestDate__c}" rendered="{!Account.TestDate__c == NULL}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:form>
</apex:page>

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

Hari.gsHari.gs

 

Hi thanks for the replay...

 

So far I have written only triggers in salesforce, I am not sure where to write this piese of code. So could you please help on that also. Please tell me the path where I can put this code try whether this is working as I wanted?

 

Thanks and Regards

Hari G S

souvik9086souvik9086

You create a visualforcepage by going to SetUp -> Develop -> New and write there

 

<apex:page standardController="Account">
<apex:form >

<apex:outputField value="{!Account.TestDate__c}" rendered="{!Account.TestDate__c != NULL}"/>
<apex:inputField value="{!Account.TestDate__c}" rendered="{!Account.TestDate__c == NULL}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:form>
</apex:page>

 

You can go to Account -> Buttons & Links -> View -> Click the edit beside it and override with the visualforce page you just created.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

Hari.gsHari.gs

 

Hi,

 

Actualy what I wanted is to disable that calendar popup button for a date field from entering a new date for a date field if a value exists in that fields. If the date field is empty I should be able to select a date from the popup.

 

Thanks and Regards

Hari G S

souvik9086souvik9086

Yes but you cannot do that while using standard account layout. You cannot give any condition for any field in the standard page layout. You can only make that field Read Only through layout. But you can't give any condition there like if it is not null there read only like this. It will become read only for all.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

This was selected as the best answer