In Salesforce, data rarely lives in isolation. To model real-world business operations, objects must connect with one another. The most flexible and widely used relationship type in Salesforce is the Lookup Relationship. Understanding how lookups work under the hood is essential for designing high-performance data models and maintaining clean security controls.
1. How Lookup Relationships Work
When you create a lookup field on an object, Salesforce adds a 15- or 18-character foreign key field referencing the parent record's Id. Lookups establish 1-to-1 or 1-to-many associations without enforcing tight lifecycle dependencies.
Asset record has a lookup field pointing to an Account. If the company updates account details, the asset stays linked. If the asset is reassigned or the company relationship ends, the asset record remains intact in Salesforce with its own owner and history.
2. Deletion Behaviors: What Happens When a Parent is Deleted?
Unlike Master-Detail relationships where deleting a parent automatically deletes all child records, Lookup relationships let you choose one of three distinct deletion behaviors:
- Clear the value of this field (Default): If the parent record is deleted, Salesforce sets the lookup field on the child record to blank (null).
- Don't allow deletion of the lookup record that's part of a lookup relationship: Blocks the deletion of the parent record if any active child records are currently referencing it.
- Delete this record also (Cascade Delete): Available only for custom lookups on custom objects via Salesforce Support or custom configurations where child deletion is explicitly required.
3. Lookup Relationships vs. Master-Detail Relationships
Choosing between a Lookup and a Master-Detail relationship is one of the most critical decisions in Salesforce schema design:
- Parent Requirement: Lookup fields can be optional; Master-Detail relationship fields are always strictly required on the child.
- Security & Sharing: In Lookups, child records have their own Owner and independent sharing rules. In Master-Detail, child records inherit all security, sharing settings, and ownership from the master parent.
- Roll-Up Summaries: Standard Roll-Up Summary fields are natively supported only on Master-Detail relationships (for Lookups, use Salesforce Flow or Apex to aggregate child data).
- Limits: You can create up to 40 lookup relationships per object, compared to a strict maximum of 2 master-detail relationships per object.
4. Querying Lookups with SOQL & Apex
Lookup relationships allow developers to traverse child-to-parent and parent-to-child data structures using dot-notation and subqueries:
// 1. Child-to-Parent SOQL Traversal (Up to 5 levels)
List<Contact> contacts = [
SELECT Id, LastName, Account.Name, Account.Industry
FROM Contact
WHERE AccountId != null
WITH USER_MODE
];
// 2. Parent-to-Child Subquery using Relationship Name (Child Relationship)
List<Account> accountsWithAssets = [
SELECT Name, (SELECT Name, SerialNumber FROM Assets__r)
FROM Account
WITH USER_MODE
LIMIT 50
];
5. Step-by-Step: Creating a Lookup Field
- Step 1: Navigate to Setup > Object Manager and select your child object.
- Step 2: Click Fields & Relationships > New and choose Lookup Relationship.
- Step 3: Select the target parent object from the Related To dropdown.
- Step 4: Specify the Field Label, Field Name, and child relationship list label.
- Step 5: Configure optional lookup filters (e.g., only show active accounts) and select your deletion behavior.
- Step 6: Set Field-Level Security (FLS) for user profiles and add the related list to the parent page layout.
Summary
Lookup relationships provide the structural backbone for flexible data modeling in Salesforce. By keeping objects loosely coupled, you maintain clean ownership hierarchies, prevent accidental cascading record deletions, and ensure your CRM schema scales efficiently as your organization grows.