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
netTrekker_ADnetTrekker_AD 

Event VR: Require Related To unless user has certain profile and record type

I posted about a basic version of this rule about a month ago and it was solved. (Thanks again Stevemo)

 

Now I need to build some exceptions into this rule. 

 

Specifically the goal of this rule is

 

"The Related To (WhatId) field of an Event is required if the Name (WhoId) is not a Lead, UNLESS the Name (WhoId) is blank AND the User's profile is one of those listed AND the Event Record Type equals the one below.

 

 

AND(NOT(LEFT(WhoId,3) = "00Q" || WhoId = "" && $Profile.Id <> "00e80000000wY2R" && $Profile.Id <> "00e80000001K2s9" && $Profile.Id <> "00e80000000xKQi" && $Profile.Id <> "00e80000000xJTh" && $RecordType.Id <> "012Q000000009ZN" ), LEN(WhatId) < 1)

 

 

 

 

What do I have wrong??

 

Thanks! 

Best Answer chosen by Admin (Salesforce Developers) 
Steve :-/Steve :-/

Okay, I think I've got it

 

AND(NOT(LEFT(WhoId,3) = "00Q"),

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

NOT($Profile.Name = "Standard User"),

NOT($Profile.Name = "Solution Manager"),

NOT($Profile.Name = "Marketing User"),

NOT($RecordType.Name = "Test Task" ),

OR(LEN(WhoId) < 1,

LEN(WhatId) < 1))

 

 

 

Message Edited by Stevemo on 03-04-2010 04:20 PM

All Answers

Steve :-/Steve :-/

Here you go

 

 

 

AND(NOT(LEFT(WhoId,3) = "00Q"),

LEN(WhatId) < 1,

LEN(WhoId) < 1,

NOT($Profile.Name = "ExemptProfile_1"),

NOT($Profile.Name = "ExemptProfile_2"),

NOT($Profile.Name = "ExemptProfile_3"),

NOT($Profile.Name = "ExemptProfile_4"),

NOT($RecordType.Name = "ExemptRecordType_1" ))

 

 *  You should ALWAYS use $Profile.Name and $RecordType.Name instead of the Profile ID and Record Type ID

 

 

oh yeah, you owe me one of these...

http://www.russianriverbrewing.com/web/brews/plinytheelder.htm

 

actually, make it TWO!!!  

 

Message Edited by Stevemo on 03-04-2010 12:51 PM
netTrekker_ADnetTrekker_AD

Thanks again!

 

Unfortunately neither you nor I can get Pliny the Elder. Now if you can find a beer you like that Ohio can get that MA cannot, let me know and I might be inclined to ship one or two out. At the company's expense of course haha. We basically just have Christian Moerlein, Great Lakes, Hoppin Frog, Fat Heads, BarrelHouse Brewing, Mt. Carmel Brewery, etc. Christian Moerlein, BarrelHouse, and Mt. Carmel Brewing are all local...

Steve :-/Steve :-/

If they brew an Imperial or Double I.P.A. I'm in!!!

 

Cheers! 

netTrekker_ADnetTrekker_AD

Uhhh Ohhh, no beers yet....

 

So I put this rule in place, logged in as a user who has one of the exempt profiles, and was able to log an event using a different record type than the exempt one, and it allowed me to do so without anything in the WhoID or WhatID fields. I need the rule to work for those users with those four profiles if they use a different record type from the exempt one.

Steve :-/Steve :-/
Okay, we're still close I think just misunderstood what you were trying to do in terms exemptions and validations.  
netTrekker_ADnetTrekker_AD

Basically, The users in those profiles will have two Event Record Types to choose from. When they use the one built into the rule, I want it to be OK for them to Save the Event without any WhoId or WhatId. If they use the other record type, not mentioned in the rule, I still want the rule to mandate that if there is a Contact in WhoId, then WhatId cannot be blank.

 

Thanks again.

Steve :-/Steve :-/
If that's the case, then we could probably strip out the Profile references, since the VR is really tied to the Record Type
Steve :-/Steve :-/

Okay, try this one (you'll have to change the Profile and RecType references to match your SFDC.Org)

 

 

AND(NOT(LEFT(WhoId,3) = "00Q"),

LEN(WhoId) > 1,

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

NOT($Profile.Name = "Standard User"),

NOT($Profile.Name = "Solution Manager"),

NOT($Profile.Name = "Marketing User"),

NOT($RecordType.Name = "Test Task" ),

LEN(WhatId) < 1)

 

 

 

Message Edited by Stevemo on 03-04-2010 03:12 PM
netTrekker_ADnetTrekker_AD

To your point about the profiles, can I just use the rule above and remove the four profiles since they will be the only ones to see that record type anyways?


That way the rule will just work to enforce unless the record type is that specific one?

Steve :-/Steve :-/
The modifed VR that I posted should cover everything now.  I was just thinking that if the requirement is more directly tied to the TYPE of Activity Record that is being created rather then WHO is creating it, then you could simplify the VR and remove the Profile references.   
netTrekker_ADnetTrekker_AD

I put in the rule exactly as you have it in the most recent code box and replaced the generics with our specifc profiles and record type. Logged in as a user with one of the profiles, logging an event with the record type not excluded, I was able to still save without the required Name and Related To field.

 

I apologize, I just wish I understood this stuff better. 

Steve :-/Steve :-/

no problem, we're really close, just have to get the Include and Omit stuff sorted.

 

My VR is coded to say IF the activity is NOT related to a Lead (WhoId) and it IS related to a Contact (WhoId), 

and the User is NOT exempted by Profile ($Profile.Name),

and the activity is NOT exempted by Record Type($RecordType.Name),   

then the Activity MUST be related to another type of record (WhatId)

 

is that what you're after? 

netTrekker_ADnetTrekker_AD

To add to it,

 

The rule works correctly if there is a Contact in the WhoId field. In this case, if I log an Event with the excluded record type, I can save it successfully either with or without anything in the WhoId. 

 

The issue is if I log an event with the other record type that should get flagged, I can save it successfully without the WhoId and WhatId. If I attempt to save it with only the WhoId being a Contact, it throws the error. I need it to throw the error when this record type is used and both are blank.

netTrekker_ADnetTrekker_AD
Yes this is what I am after except that the rule needs to flag when both the WhoId and WhatId are blank, using the non-excluded record type. Does that make sense?
Steve :-/Steve :-/

Okay, I think I've got it

 

AND(NOT(LEFT(WhoId,3) = "00Q"),

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

NOT($Profile.Name = "Standard User"),

NOT($Profile.Name = "Solution Manager"),

NOT($Profile.Name = "Marketing User"),

NOT($RecordType.Name = "Test Task" ),

OR(LEN(WhoId) < 1,

LEN(WhatId) < 1))

 

 

 

Message Edited by Stevemo on 03-04-2010 04:20 PM
This was selected as the best answer
netTrekker_ADnetTrekker_AD

Got it!

 

That deserves a beer for sure!