1

Related to my previous question: How to make accounts read-only / locked?

I'm trying to prevent changes from being made to accounts with a certain record type.

One possible change a user could make is to the list of related objects (e.g. its contacts). Accordingly, I'm trying to write a validation rule for these object types that prevents them from being either added to or removed from these records. I thought the following would work:

AND(
    OR(
        Account.RecordTypeId = "0124E0000000fKD",
        PRIORVALUE(Account.RecordTypeId) = "0124E0000000fKD"
    ),
    OR(
        ISCHANGED(AccountId),
        ISNEW()
    )
)

But a get a syntax error:

The PRIORVALUE function cannot reference the Account.RecordTypeId field

Some Googling reveals that others have had similar problems (e.g. this thread).

So: what's the right way to check the record type of the previously linked account?

1
  • 1
    Can you have a formula field for capturing recordtype and use it in you validation rule with PRIORVALUE function?
    – Raul
    Mar 28, 2017 at 14:38

1 Answer 1

2

The Account isn't being modified, so checking its previous value doesn't make any sense. It didn't change! Just remove that part of your formula:

AND(
    Account.RecordTypeId = "0124E0000000fKD",
    OR(
        ISCHANGED(AccountId),
        ISNEW()
    )
)

I recommend you also filter on RecordType.DeveloperName. It makes your validation less brittle as it should work in all your environments, and also much easier to read:

Account.RecordType.DeveloperName = "Some_Record_Type_You_Can_Read"
6
  • Ah, OK. That makes sense, but it shifts my problem. How can I detect when (e.g.) a contact was linked to an account of a certain type, but has been removed?
    – Tom Wright
    Mar 28, 2017 at 14:44
  • The Contact has been removed? What do you mean? Deleted? Orphaned?
    – Adrian Larson
    Mar 28, 2017 at 14:46
  • Sorry Adrian - I mean moved onto another account.
    – Tom Wright
    Mar 28, 2017 at 14:47
  • That's why you have ISCHANGED(AccountId).
    – Adrian Larson
    Mar 28, 2017 at 14:47
  • 1
    @TomWright The rule would need to fire on Contact, NOT Account. Only IsChanged(AccountID) would apply to the field on Contact. The recordType would apply to the Account. You won't be able to reach it from Contact; at least not easily.
    – crmprogdev
    Mar 28, 2017 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .