2

I have a number of validation rules on Accounts, and now I want to exclude all accounts that have been created before 2014. Instead of entering the date criteria into every validation rule, I was wondering whether it is somehow possible doing this using a custom setting? Like that I can refer to the custom setting in the validation rules, and if I need to make changes to the date, I only have to do it in one place. Any ideas how I can do that?

2

If you create a Custom Setting of a Hierarchy type, you'll be able to access this setting inside validation rules. List Custom Settings are not usable inside validation rules, however. Add a field to the setting of a DateTime or Date type, say Editable_Date__c, and then set a Default Organization Level Value, to say, 1/1/2014.

Inside your validation rule, you'll be able to write something like the following:

$Setup.DateCustomSetting__c.Editable_Date__c >= CreatedDate

|improve this answer|||||
  • Doesn't this require to modify all the validation rules? I think the question is about if it is possible to avoid modification of every validation rule – Patlatus Jun 1 '16 at 14:39
  • To add a custom setting to each validation rule, you will have to edit each rule regardless to make the changes. Once the setting is in place, any further changes to the dates used (Such as changing the year from 2014 to 2015), will only require modifying the custom setting, and not each validation rule individually. – battery.cord Jun 1 '16 at 14:44
  • 2
    This is definitely the best way to go imo. $Label seems very brittle since you can't take advantage of strict typing. – Adrian Larson Jun 1 '16 at 16:22
  • I am sorry, I may have expressed myself a bit unclear. I don't want to add a date value into each validation rule, because then I would have to update each validation rule again, if I wanted to change the date. So custom setting is the way to go I think. I can add that to each validation rule once and then that's it – Lily Jun 1 '16 at 18:59
  • I have tried this now. I created a custom setting and a Date/Time field in the custom setting. As a default value in the date/time field I wrote: 2014-01-01 00:00:01. I get the error message: Error: Syntax error. Extra '00' When I remove the time part from the date/time value, I get: Error: Formula result is data type (Number), incompatible with expected data type (Date/Time). what am I doing wrong? – Lily Jun 1 '16 at 19:04
1

Just a quick idea (haven't tested it yet).

You could try and save the date in a Custom Label (Creating Custom Labels) and refer to that label in your validation rule:

 $Label.YourLabelName

This will obviously be text, so you will need DATEVALUE() formula to parse it to a date format your validation rule will understand, see Documentation on DateValue formula.

So, let's say you created your label called ValidationDate and filled it with "2014-06-01", then you could try the following validation rule:

CreatedDate < DATEVALUE($Label.ValidationDate)

Just expand this formula to your requirements.

|improve this answer|||||
  • Hello ,thats a great idea. I have created a custom label, however I get an error message now: Error: Incorrect parameter type for operator '<'. Expected DateTime, received Date. This is strange, because I have actually put a datetime value into the custom label: 2014-01-01 00:01:01 – Lily Jun 1 '16 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.