# How do Lookup relationships differ from Master-Detail relationships in terms of record dependency and security?

**Topic:** Admin · **Difficulty:** Medium · **Tags:** Admin, Object Relationships, Lookup Relationship

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-lookup-relationships-differ-from-master-detail-relationships-in-terms-of-record-dependency-and-security

## Answer

**Basics:** A lookup field is simply a pointer to another record, for example Contact to Account or a custom Project to Account. It models "is related to" rather than "belongs to".

**How it works:**
- The field can be optional (default) or required.
- Each child has its own Owner and its own sharing based on its own organization-wide default.
- Deletion behavior when the parent is deleted: Clear the value (default), Don't allow deletion (restrict, so the parent cannot be deleted while children exist), or, for certain custom-object cases, cascade delete (enable-by-request in some orgs).
- Lookup filters can limit which parent records are selectable.

**Advanced / deep dive:** Comparison:
- Dependency: lookup optional; master-detail required.
- Security: lookup child has own owner/OWD; master-detail child inherits parent sharing.
- Roll-ups: native roll-up summary fields work only on master-detail. For lookup, use a record-triggered flow, an Apex trigger with aggregate queries (`SELECT ParentId, SUM(Amount__c) ... GROUP BY ParentId`), Declarative Lookup Rollup Summaries (open source), or a Data Cloud/CRM Analytics approach.
- Limits: an object can have a larger number of lookups than master-detail (two), though total relationship counts are limited; verify against the object's limits.
- Reporting: both enable cross-object reports through report types; "with/without" is available through relationships.
- Conversion: lookup to master-detail requires every record to have a parent. Master-detail to lookup requires removing roll-ups and is allowed afterward.
- Self-lookup and polymorphic (WhoId/WhatId) are lookup-type behaviors.

**Code / config example:**
```apex
// Lookup roll-up replacement: bulk-safe count of open Cases per Account
Map<Id, Integer> counts = new Map<Id, Integer>();
for (AggregateResult ar : [SELECT AccountId a, COUNT(Id) c FROM Case
                           WHERE AccountId IN :accountIds AND IsClosed = false
                           GROUP BY AccountId]) {
    counts.put((Id) ar.get('a'), (Integer) ar.get('c'));
}
```

**Hidden gotchas & must-remember points:**
- Default delete behavior clears the lookup silently, leaving orphaned children without parent, which surprises reports.
- A required lookup is only enforced by the field, not by the platform dependency; API and data loads still must supply it.
- Lookup children do not inherit sharing, so a user can see a child but not the parent, causing blank related-name fields.
- Cascade delete on lookups is not available for standard-object lookups.
- Changing the delete option to restrict can break data cleanup and integration jobs.

**Best practice:** Default to lookup and move to master-detail only for true parent-child lifecycles and when you need roll-ups or inherited security.

---
Source: ForceChallenges · last updated 2026-11-02
