+ Start a Discussion
cldavecldave 

conditional validation rule

Hi i'm trying to re-write this formula and having some syntax issue :(

 

Old rule condition was : if 1st established contact already contains a date, canot change it

 

New rule condition is as follow: If established 1st contact is WITHIN last 3 months, that date cannot be changed with exception for admin

 

 

Here is old formula without new condition

 

 

AND(
NOT($Profile.Name = "System Administrator"),
ISCHANGED(Established_1st_Contact__c),
NOT(
ISBLANK(
PRIORVALUE(Established_1st_Contact__c))))

 

 

If nayone can help, i would appreciate

 

 

Thx in advance

Best Answer chosen by Admin (Salesforce Developers) 
AgiAgi

Hi,

 

you can use the id of the profile instead of the name in the condition,

 

AND(
$User.ProfileId <> "sys admin profile id",
ISCHANGED(Established_1st_Contact__c),
Today()-PRIORVALUE(Established_1st_Contact__c) <= 90 )

All Answers

Kent ManningKent Manning

Hi cldave,

 

Did the "old" rule work properly?

 

What is the nature of the syntax error?

 

The formula that you have written is correct in terms of the ANDs, NOTs, and ISBLANK,ISCHANGED, and PRIORVALUE. You also have the right number of parenthesis.  Only thing you might want to try is change "System Administrator" to 'System Administrator' - use single quote instead of double quotes to see if that helps.  Otherwise, let me know the nature of the syntax error so that I can better troubleshoot the rule. 

cldavecldave

Yes sorry if i was not clear,  It is a working rule, but the condition need to change, as shown on old rule condition is: If field (date) not = to blank , cannot be changed

 

Now i need to modify this rule condition  to this instead:

 

If field(date) within last 90 days , field cannot be changed

 

Basically only allow to change date on this field if older than 90 days

 

Kent ManningKent Manning

I don't know what you have tried so far, but you might try this modification:

 

AND(
NOT($Profile.Name = "System Administrator"),
ISCHANGED(Established_1st_Contact__c),
IF(NOT(ISBLANK(PRIORVALUE(Established_1st_Contact__c))),Today() - Established_1st_Contact__c =< 90, False))

 

Does that get you to your stated goal?

 

 

cldavecldave

yes that is what i need in theory , unfortunately this formula gives me the following error:

 

Error: Syntax error. Found '<'

 

Thank you very much for taking the time to help me, I really suck in formulas and trying to learn :)

Kent ManningKent Manning

Hi cldave,

 

Change the formula to reflect what is shown in red below.  That should work.

 

AND(
NOT($Profile.Name = "System Administrator"),
ISCHANGED(Established_1st_Contact__c),
IF(NOT(ISBLANK(PRIORVALUE(Established_1st_Contact__c)

)),(Today() - Established_1st_Contact__c) <= 90, False))

cldavecldave

Unfortunately it seems this formula is not bringing me the result i'm looking for :(

 

Example: I take a blank lead mark date of 1st established contact as: 01/01/2013 and try to change it to any date value not in the last 90 days and it lets me

 

But if i try to change it TO a date in the last 90 days it does not let me, even tho previous date is clearly over last 90 days

 

For clarity purposes: i want the rule to adhere to the following condition in both order:

 

Allow changes if conditions met:

- Field blank

-Date older than last 90 days

 

or

 

Do not allow changes if conditions met:

 

-Date in field is within last 90 days

 

 

Sorry to be a bother and hope you can help

 

 

 Thx

 

 

Kent ManningKent Manning

How about trying this modification to your fomula:

 

AND(
NOT($Profile.Name = "System Administrator"),
ISCHANGED(Established_1st_Contact__c),

 

IF((Today() - Priorvalue(Established_1st_Contact__c))>=90, False, True),


IF(NOT(ISBLANK(PRIORVALUE(Established_1st_Contact__c)

)),(Today() - Established_1st_Contact__c) <= 90, False))

AgiAgi

Hi,

 

you can use the id of the profile instead of the name in the condition,

 

AND(
$User.ProfileId <> "sys admin profile id",
ISCHANGED(Established_1st_Contact__c),
Today()-PRIORVALUE(Established_1st_Contact__c) <= 90 )

This was selected as the best answer
cldavecldave

Ty very much guys , finally that last post from Agi worked!

 

:)