You need to sign in to do that
Don't have an account?
A validation rule enforcing the hierarchy between Accounts´ record types
Hi there,
we need a validation rule on accounts which would make sure that the newly created account is connected to a parent account with the hierarchically higher level.
This is the record type hierarchy:
1st (highest level)= consolidated BP
2nd= BP
3rd= invoice acc
4th= delivery acc
and this is the formula I am trying to play around:
IF(
AND(
NOT(ISNULL(ParentId)),
RecordType.Name = "Invoice Acc",
Parent.RecordType.Name = "Delivery Acc"
), true,
IF(
AND(
NOT(ISNULL(ParentId)),
RecordType.Name = "Delivery Acc",
Parent.RecordType.Name= "BP"
), true,
IF(
AND(
NOT(ISNULL(ParentId)),
RecordType.Name = "BP",
Parent.RecordType.Name= "Consolidated BP"
), true, false
)
)
)
But it is not working...there is always a syntax error...
Could you help me? Is this possible at all, or is there a workaround?
thanks!
We're going to get this, I promise!
First, I realized I made a mistake earlier when I suggested Name should be the API name. When I double-checked, it turns out that unlike most other metadata, RecordType.Name is the label and RecordType.DeveloperName is the API name (with the underscores). I apologize for leading you astray there.
Second, I noticed that in your first description of the problem, your hierarchy was as follows:
but it looks like you've got Invoice Acc and Delivery Acc switched around in your formula.
With all that in mind I tried this, and it seems to work:
Let me know how that works for you.
All Answers
The error is because you can't get to the Parent Record type that way. Here is an Answers post by @SteveMo that describes a way to accomplish this. https://success.salesforce.com/questionDetail?qId=087300000006xBYAAY
As of the Spring '13 release, $RecordType is deprecated and we support RecordType as a cross-object reference, even in validation rules (rendering Steve's solution obsolete).
I don't get a syntax error when I paste your formula into a validation rule. However, I notice that you are referencing RecordType.Name but the value you're comparing it to looks like the label -- names don't have spaces in them.
Can you post the content of your syntax error?
Hi again,
I am actually not getting a syntax error any more...
After I put the name in the inverted commas, instead of labels (thanks @shale), the validation rule still does not work...
IF(
AND(
NOT(ISNULL(ParentId)),
RecordType.Name = "Invoice_Acc",
Parent.RecordType.Name = "Delivery_Acc"
), true,
IF(
AND(
NOT(ISNULL(ParentId)),
RecordType.Name = "Delivery_Acc",
Parent.RecordType.Name= "BP"
), true,
IF(
AND(
NOT(ISNULL(ParentId)),
RecordType.Name = "BP",
Parent.RecordType.Name= "Consolidated_BP"
), true, false
)
)
)
so I guess it is the logic that is not correct.
Does anyone have an idea of what should be changed?
Thanks!
Try replacing ISNULL() with ISBLANK(). ISNULL() doesn't have the behavior you'd expect with strings (they are not "null" when empty), so I recommend always using ISBLANK() instead.
Let me know if that doesn't work and I'll take a deeper look later this morning.
Thanks @shale!
I have continued working on this and the latest version is:
IF(OR
(
AND(
NOT(ISBLANK(ParentId)),
NOT(AND(RecordType.Name = "Invoice_Acc",
Parent.RecordType.Name = "Delivery_Acc"
))),
AND(
NOT(ISBLANK(ParentId)),
NOT(AND(RecordType.Name = "Delivery_Acc",
Parent.RecordType.Name= "BP"
))),
AND(
NOT(ISBLANK(ParentId)),
NOT(AND(RecordType.Name = "BP",
Parent.RecordType.Name= "Consolidated_BP"
)))
), false, IF (ISBLANK(ParentId), false, true))
unfortunatey, it still does not work as it should...
We're going to get this, I promise!
First, I realized I made a mistake earlier when I suggested Name should be the API name. When I double-checked, it turns out that unlike most other metadata, RecordType.Name is the label and RecordType.DeveloperName is the API name (with the underscores). I apologize for leading you astray there.
Second, I noticed that in your first description of the problem, your hierarchy was as follows:
but it looks like you've got Invoice Acc and Delivery Acc switched around in your formula.
With all that in mind I tried this, and it seems to work:
Let me know how that works for you.
Thanks @shale, both for resolving this and explaining it so clearly. I´ve learned a lot!
You're welcome! Glad I could help.