Salesforce: Lookup Filter for Different Record Type

Scenario:

How to limit a lookup field to only show certain records based on record type. For example, an account has 2 record type – HQ & Branch. Each branch will need to specify the HQ using the Parent Account field:

HQ (Parent Account)
Branch 1
Branch 2
Branch 3

Based on the example above, we need to apply restriction:

  • A Branch account cannot have another branch account as the parent.
  • An HQ account cannot have a branch as parent account.

 

Solution #1: Lookup filter (Recommended)

You can use lookup filter to limit the selection based on record type. For example:

Filter criteria:
  1. Account record type = Branch
  2. Parent account record type = HQ
  3. Account record type = HQ
  4. Parent account record type = HQ
Filter logic:
(1 AND 2) OR (3 AND 4)Note!: Make sure that filter type is set to Required to make sure that the lookup value MUST match criteria!

Solution #2: Validation

You can also choose to create a set of validation rule to stop the user from saving a record. For example:

OR(
AND(RecordType = Branch, NOT(ParentAccount.RecordType = HQ)),
AND(RecordType = HQ, NOT(ParentAccount.RecordType = HQ))
)

Both solutions above will trigger on bulk insert/update. You will probably get the below error when you try to assign parent account that doesn’t fit the criteria:

  1. ERROR: Value does not exist or does not match filter criteria  OR
  2. The error message you set in the validation rule

Get in touch today to see how WDCi can help your business.