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
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:
-
Account record type = Branch
-
Parent account record type = HQ
-
Account record type = HQ
-
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!
(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:
- ERROR: Value does not exist or does not match filter criteria OR
- The error message you set in the validation rule