How to fix my validation rule that stops users under a profile from changing Lead Source? - Answers - Salesforce Trailblazer Community
Ask Search:
Caterina TorresCaterina Torres 

How to fix my validation rule that stops users under a profile from changing Lead Source?

Right now, I have a validation rule that stops users under a specific profile from changing the lead source on a lead. However, how can I fix it so if the Lead Source was blank, they can select a value and save the record?
 
AND ( 
ISCHANGED(LeadSource), 
NOT(ISBLANK(TEXT(LeadSource))), 
$Profile.Id = '00ed0000001EST8' 
)

 
Best Answer chosen by Caterina Torres
Deepak AnandDeepak Anand
Try this = 
AND(
    ISCHANGED(LeadSource),
    OR(
        AND(
            NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource)))),
            ISBLANK(Lead_Lead_Source__c)
        ),
        TEXT(PRIORVALUE(LeadSource)) <> Lead_Lead_Source__c
    ),
    $Profile.Name = "Custom Standard User"
)

All Answers

Deepak AnandDeepak Anand
Try this = 

Tip: Use Profile Name always :-)
AND(
    ISCHANGED(LeadSource),
    NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource)))),
    $Profile.Id = "00ed0000001EST8"
)
Caterina TorresCaterina Torres
ok, new requirement and I need help creating a validation rule. I need to allow the profile to change the Lead Source ONLY IF text field Last_Lead_Source__c is populated and not is blank

Current Rule:
AND( 
ISCHANGED(LeadSource), 
NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource)))), 
$Profile.Name = "Custom Standard User" 
)

 
Deepak AnandDeepak Anand
I am confused. So we just need to look into this new field now ?
Caterina TorresCaterina Torres
Let me clarify:

We do not want the Custom Standard User to be able to change the Lead Source (unless the value was blank before). However, we have a team of people in that profile that need to be able to change the Lead Source as long as they populate a value onto the text field Last_Lead_Source__c

User-added imageUser-added image
Caterina TorresCaterina Torres
I think I figured it out 
AND(
    ISCHANGED(LeadSource),
    NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource)))),
    ISBLANK(Last_Lead_Source__c),
    $Profile.Name = "Custom Standard User"
)
Deepak AnandDeepak Anand
Try this = 
AND(
    ISCHANGED(LeadSource),
    NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource)))),
    ISBLANK(Lead_Lead_Source__c),
    $Profile.Name = "Custom Standard User"
)
Caterina TorresCaterina Torres
We're on the same page. But now I need to make sure they do not change the Lead Source again afterward.....
Deepak AnandDeepak Anand
Ah! This is getting complicated ;-)

So when both Lead Source and Last Lead Source are filled, we should stop them ?

 
Caterina TorresCaterina Torres
Yes. I wrote this, but need to test it still
OR (
  AND(
    ISCHANGED(LeadSource),
    NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource)))),
    ISBLANK(Last_Lead_Source__c),
    $Profile.Name = "Custom Standard User"),
  AND(
    ISCHANGED(LeadSource),
    NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource)))),
    NOT(ISCHANGED(Last_Lead_Source__c)),
    $Profile.Name = "Custom Standard User")
)

 
Deepak AnandDeepak Anand
Wait! If they change the Last Lead Source, then are they OK to change the Lead Source ?

Sorry. I am lost :-(
Caterina TorresCaterina Torres
Sorry =(

The Custom Standard User cannot change Lead Source unless they enter in a value for Last Lead Source
After that, they cannot edit Lead Source UNLESS they update Last Lead Source again. I hope that helps.
Deepak AnandDeepak Anand
Ah! Then you are doing it incorrectly. Why ask the User to copy and paste the Lead Source when you can automate it ?

I would do it like this = 
  1. Create a Workflow Rule + Field Update to capture the last Lead Source when there is a change
  2. Create a Validation Rule that prevents the Users from setting it to EMPTY. I would even avoid a Validation Rule and instead mark it required on the Page Layout
This way User can still change the Lead Source and the last one is automatically captured plus they cannot leave it empty.

What say ?
Caterina TorresCaterina Torres
The case does not always call to copy the Lead Source over to Last Lead Source, thus why only a certain team is doing this manually. We want to stop people from changing Lead Source UNLESS a specific reason calls for it. 
Deepak AnandDeepak Anand
Try this = 
AND(
    ISCHANGED(LeadSource),
    OR(
        AND(
            NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource)))),
            ISBLANK(Lead_Lead_Source__c)
        ),
        TEXT(PRIORVALUE(LeadSource)) <> Lead_Lead_Source__c
    ),
    $Profile.Name = "Custom Standard User"
)
This was selected as the best answer
Caterina TorresCaterina Torres
This works! Thanks.
Deepak AnandDeepak Anand
Awesome!

Happy weekend :-)