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
KevinA.ax1880KevinA.ax1880 

Referencing a field in a class.

Hi,

 

I am very new to APEX, and am trying different ways to raise an error to my users.  In the current situation, I am attempting to prevent a user from removing/clearing out a date field, once they have set a date. 

 

I received some help originally to manipulate child records, created in a class object which I have extended for some validation in which I have a custom exception working that raises an error to the user displayed at the top of the form.

 

The problem with this option (that I can see) is that it throws an exception with allot of additional language included.  I remember in my administration clas they mentioned raising errors attached to a specific field, but for the life of me cannot come up with a solution.

 

Does anyone have a specific example they could share that could be used as a validation step that raises a custom message on a specific field?

 

 - Thanks, Kevin

CNimmaCNimma

A simple validation rule should do the job. Create a validation rule and enter the error condition formula as ISCHANGED(Field Name). You can select the option to display the error message next to the field or top of the page. Hope this helps.

KevinA.ax1880KevinA.ax1880

CNimmaCNimma
The above formula prevents the date from editing and deleting once a date value is entered. Is this not what you are looking for? Please try it once and see how it works.
KevinA.ax1880KevinA.ax1880

Thanks for the response.  I have given it a shot, but it prevents someone from initially entering a date in the field, since it is changing from blank to a date.  This is why I think there needs to be some evaluation of what the field was originally.

 

Please let me know if you may have an idea of how to check not only that the user changed the value, but that they are removing contents from a field that someone at one point had populated.

 

Also, if you know of a good resource for questions like these, I would love to hear it!

CNimmaCNimma
Please try this formula, this should work.
AND(
NOT( ISNEW() ),
TEXT((PRIORVALUE( Date__c )))<>"",
ISCHANGED( Date__c )
)
KevinA.ax1880KevinA.ax1880
This worked perfectly. Thanks!

Would you have a good resource for figuring all of this out? I have a .Net/SQL background.