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
MSVRadMSVRad 

Validation Rule Help

Setup:

 

I have two types of accounts pracs and facs. The prac accounts are the parent of the fac accounts. On the fac page there is a field called parent account (Standard field) where the user enters the prac as the parent. It is a lookup field.  The pracs and facs have different record types. 

 

Validation rule requirements:

The validation rule that I want to write is to prevent a user from linking a fac to a fac because a fac CANNOT be a parent. So when a user clicks on an account to be the parent account is there a way to check the record type of that account to make sure it is of type prac before allowing a save? I would rather not write a trigger for this since our business model is somewhat complicated but I am willing to look at it as an option.

 

Any suggestions would be greatly appreciated! Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf
You can make a validation rule based on the record type ID.  See here.

All Answers

werewolfwerewolf
You can make a validation rule based on the record type ID.  See here.
This was selected as the best answer
melissapgpmelissapgp

Try a validation rule like

 

AND(

RecordTypeId = FAC,

Account.Parent.RecordTypeId = FAC)

MSVRadMSVRad
Thanks for the help - the extra characters threw me off. The validation rule works now.
werewolfwerewolf
For the record, melissapgp, what you suggested there would not work -- you have to compare the RecordTypeId to an actual ID value, not the name.  See the link to the other board post I wrote for instructions on how to do that.
melissapgpmelissapgp
haha... I guess I need to be more specific when posting around here. Because I was calling out the ID field, I had thought that it would be assumed they would use the Record type ID and not the Record Type name  ;)
MSVRadMSVRad

Here is another question for you two. The validation rule I wrote for the account object worked just fine but what I did not realize is that even though this validation rule is in place when a lead is converted containing a field that maps to the parent field on the account object. If it is not of type prac it does not matter it is still accepted and saved. So...

 

I have a field called Prac Account on my lead object which is a lookup field when clicked all accounts appear in it.  Is there a way to write a validation rule using the RecordTypeIds that I have for the account object for the lead?

 

IsPickVal(Account_Type__c, 'fac')

then the Prac_Account__c has to be an account of type prac.

 

The Prac_Account__c field is a lookup field that is related to the Account object

 

I have tried many different approaches to this and have not come up with a solution that works. Will this only work if the record types are for the Lead object and not the account object?

Message Edited by MSVRad on 05-27-2009 11:30 AM
melissapgpmelissapgp

I have a similar issue.  I need to enforce Billing address validation rules upon Lead Convert.

 

There is a feature that allows you to enforce Validation rules on Lead Convert but realize that it's not just Validation rules for Accounts, it's validation rules for Opportunities and Contacts as corresponding records may get created.

 

I asked my Premier Support Rep about it and he suggested fully testing it out in Sandbox prior to implementing it as it may be buggy.

 

To get this activated, you will need to open a ticket with Support as it needs to be activated from the backend

 

Here's another post talking about these validation rules.

http://forums.sforce.com/sforce/board/message?board.id=apex&message.id=8969

 

Hope this helps.

 

 

 

 

melissapgpmelissapgp

Sorry, I just re-read your message. 

 

You should be able to create the Validation rule on the Lead Object that would give you the error

 

 ISPICKVAL(Account__r.Type,"FAC")

MSVRadMSVRad

actually account_type__c is a custom field that I have in place on my lead object its nothing more than a picklist with fac and prac in it.  It is the Lookup Prac_Account__c field that I am looking to validate - I want to know what type of account is being "lookedup" and selected. So, which recordtypeID does it have - fac: 0127xxxxxxxxxxxG  or prac: 127xxxxxxxxxxxB.  So far I have not been successful because the recordtypeIds are for the account object not the lead object so the lead I guess is not recognizing them.

 

here is what I wish would work:

 

AND(ISPICKVAL(Account_Type__c, "Fac"),

Prac_Account__c.RecordTypeID = "127xxxxxxxxxxxG") <--- this does not work it says it does not recognize Prac_Account__c as a field even though I use it in another validation rule that is already existing and functioning.

 

then throw an error "Prac Account must be a Prac"        

 

But I will be sure to read the link you supplied above.

melissapgpmelissapgp

If you're trying to check on a value within the Account you're looking up, you will need to make sure you're referencing it properly.  Whenever you're building the validation rules, and you're inserting the fields, you will notice that some of them have a ">" which means its a lookup into another object.  At which point, you have the option to validate on a field within that lookup field's object.

 

 

So for your Prac_Account__c lookup field in the Lead Object, the correct way to reference that Account's Record Type Id in a Lead Validation rule is to use: Prac_Account__r.RecordTypeId.

 

I think all you need to do is change your __c to a __r

 

MSVRadMSVRad
Perfect. I didn't realize that the little extension to the end of the field name would make that big of a difference. I will have to look into that a little more. Thanks for the help, I really appreciate it!
Mike McKendrickMike McKendrick
How to create a validation rule on case object so that when a new case is created on an account (Lookup field) and the reason is "Stock" (Picklist field) that only one users can create this case?