Salesforce creates the underlying foreign key automatically when an admin adds a Lookup or Master-Detail field. The decision points are the relationship type, the parent object, and the field name.
- Open the child object's Fields page
Setup, Object Manager, pick the child object, click Fields and Relationships, then New.
- Pick Lookup or Master-Detail
Lookup for soft relationships (Account-Contact-like); Master-Detail for tight ownership inheritance (Invoice-Line-Item-like).
- Choose the parent object
Select the object the foreign key points to. Multiple lookups to the same parent are allowed (a deal can have a Primary Account and a Billing Account).
- Configure label, name, and reparenting
Set the field label and API name. For Master-Detail, decide whether Allow Reparenting is on; that decision is hard to reverse.
- Set the parent-delete behavior (Lookup only)
Pick Don't Allow Deletion, Clear the Field, or Cascade Delete. Master-Detail always cascades.
- Add to page layouts and FLS
Add the field to the relevant page layouts and set field-level security on every profile that needs read or edit access.
Lookup or Master-Detail; decides the FK semantics.
The object the foreign key points to.
User-facing label and programmatic identifier.
Don''t Allow, Clear, or Cascade. Default is Clear.
- Master-Detail relationships are hard to convert to Lookup later; the child cannot exist without a parent. Plan the relationship type carefully before populating data.
- Cascade Delete on a Lookup is enabled only by Salesforce Support and only on certain standard objects. Custom-to-custom Lookups cap at Clear or Don''t Allow.
- Polymorphic foreign keys cannot be queried with dot notation across all possible parents; use TYPEOF or query each parent type separately.
- External ID fields can be set to Unique. The constraint applies even when the field is on multiple records with the same value via Person Account/Account dual storage; watch the edge cases.