2

Hopefully I didn't botch the title.

I have a validation rule in place that prevents any ownership reassignments on a certain profile if they do not own the record. We don't care if they change records out of their name to someone else, but we do not want them changing records they don't own into their name. We have this working.

We have an incoming lead queue that assigns these new records into a queue name called "Unassigned Leads".

Here is our current validation rule that works as expected:

AND ( $Profile.Id = "00ej0000000hQQj" 
,ISCHANGED(OwnerId) 
,OwnerId = $User.Id )

We want the above rules to apply, along with letting our sales staff be able to change these "Unassigned Leads" into their name even though they do not own them. How can I accomplish this?

1

You can add a negative criterion that references the value of the OwnerId field prior to the change to determine if ownership is moving to a User from a Queue. Ensure that criterion evaluates to false within your AND() function so the validation rule won't block such a move.

AND(....
    PRIORVALUE(OwnerId) != "QUEUE_ID_HERE"
   )

It's a fragile solution (referencing sObject Ids directly is not a great idea), so you can make this more general by allowing the user to take a Lead from any Queue by looking for the "00G" key prefix of the Queue object.

AND(....
    NOT(LEFT(PRIORVALUE(OwnerId), 3) = '00G')
   )

Unfortunately, the Owner:Queue.Id and Owner:Queue.Name pseudo-fields aren't supported by the PRIORVALUE() function. You can use them in a validation rule, but I was mistaken in initially suggesting you use them here. (I tested the above solution in my developer org and found it working).

  • Instead of a queue Id, you could also do: Owner:Queue.Name != "Queue Name Here", which is less fragile. – sfdcfox May 4 '18 at 23:12
  • Unfortunately this suggestion didn't work. This is what you were suggesting, correct? AND ( $Profile.Id = "00ej0000000hQQj" ,ISCHANGED(OwnerId) ,Owner:Queue.Name != "Unassigned Leads" ,OwnerId = $User.Id ) – jdids May 7 '18 at 16:00
  • @jdidsQAA I'm a bonehead and missed putting a PRIORVALUE() in there. I'll update my answer in a moment. – David Reed May 7 '18 at 17:29

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.