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
Vinod Krishnan 33Vinod Krishnan 33 

Validation rule to prevent changing project status

Hi there,

'Projects' in our world is a created object. I'm trying to put in place a validation rule to prevent users (with the exception of a few, of course) from changing the status a project out of 'In Execution'. The below code, is an attempt to prevent the status from being changed from 'In Execution' to 'Lead'. The syntax is ok. But the code does not work. I'm seeking help to fix it. Thanks a ton!

AND(
ISCHANGED(Status__c),
(PRIORVALUE(Status__c) = "In Execution"),
(ISPICKVAL (Status__c,"Lead")),
$Profile.Name <> "System Administrator",
$Profile.Name <> "Integration Profile" ,
$Profile.Name <> "Jobscience Administrator",
$UserRole.Name <>"Contract Team"
)
Best Answer chosen by Vinod Krishnan 33
SarvaniSarvani
Hi Vinod,

Try like this for adding more status values:
 
AND(
ISCHANGED(Status__c),
TEXT(PRIORVALUE(Status__c)) = "In Execution",
(ISPICKVAL (Status__c,"Lead") ||ISPICKVAL (Status,"Inquiry") ||ISPICKVAL (Status,"Proposal") ||ISPICKVAL (Status,"Lost") ||ISPICKVAL (Status,"Cancelled")),
AND(
$Profile.Name <> "System Administrator",
$Profile.Name <> "Integration Profile" ,
$Profile.Name <> "Jobscience Administrator",
$UserRole.Name <>"Contract Team")
)

Hope this helps!

Thanks

All Answers

Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Vinod,
Try this formula.
AND(
ISCHANGED(Status__c),
(ISPICKVAL(PRIORVALUE(Status__c) , "In Execution")),
(ISPICKVAL (Status__c,"Lead")),
$Profile.Name <> "System Administrator",
$Profile.Name <> "Integration Profile" ,
$Profile.Name <> "Jobscience Administrator",
$UserRole.Name <>"Contract Team"
)

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards
 
SarvaniSarvani
Hi Vinod,

Please try with below formula:
AND(
ISCHANGED(Status__c),
TEXT(PRIORVALUE(Status__c)) = "In Execution",
(ISPICKVAL (Status__c,"Lead")),
AND(
$Profile.Name <> "System Administrator",
$Profile.Name <> "Integration Profile" ,
$Profile.Name <> "Jobscience Administrator",
$UserRole.Name <>"Contract Team")
)
Hope this helps! Please mark as best if it does.

Thanks
Vinod Krishnan 33Vinod Krishnan 33
Thanks Devi and Sarvani - both your suggested solutions work 100%!
Quick follow up question - what should I add to this code for 5 more status changes? ie in addition to 'Lead', I do not want users to change an 'In Execution' project to 'Inquiry', 'Proposal', 'Lost' and 'Cancelled'. Should I just use OR functions? I tried the below but there's always a Syntax error with '(' or ')'.

 
AND(
ISCHANGED(Status__c),
(ISPICKVAL(PRIORVALUE(Status__c) , "In Execution")),
OR
(
(ISPICKVAL (Status__c,"Lead")),
​​​​​​​(ISPICKVAL (Status__c,"Inquiry")),
​​​​​​​(ISPICKVAL (Status__c,"Proposal")),
​​​​​​​(ISPICKVAL (Status__c,"Lost")),
​​​​​​​(ISPICKVAL (Status__c,"Cancelled")),
)
$Profile.Name <> "System Administrator",
$Profile.Name <> "Integration Profile" ,
$Profile.Name <> "Jobscience Administrator",
$UserRole.Name <>"Contract Team"
)
SarvaniSarvani
Hi Vinod,

Try like this for adding more status values:
 
AND(
ISCHANGED(Status__c),
TEXT(PRIORVALUE(Status__c)) = "In Execution",
(ISPICKVAL (Status__c,"Lead") ||ISPICKVAL (Status,"Inquiry") ||ISPICKVAL (Status,"Proposal") ||ISPICKVAL (Status,"Lost") ||ISPICKVAL (Status,"Cancelled")),
AND(
$Profile.Name <> "System Administrator",
$Profile.Name <> "Integration Profile" ,
$Profile.Name <> "Jobscience Administrator",
$UserRole.Name <>"Contract Team")
)

Hope this helps!

Thanks
This was selected as the best answer
Vinod Krishnan 33Vinod Krishnan 33
Sarvani - thanks a ton! works beautifully!