You need to sign in to do that
Don't have an account?
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
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.
Hi CNimma,
The requirment is that the field cannot be changed from having a date, to NULL or not having a date. Thanks for reminding me about the validation rules. Is [Field].OldValue or something similar available to use in a validation rule?
- Thanks, Kevin
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!
AND(
NOT( ISNEW() ),
TEXT((PRIORVALUE( Date__c )))<>"",
ISCHANGED( Date__c )
)
Would you have a good resource for figuring all of this out? I have a .Net/SQL background.