6 - Object Relationships (Lookup and Master-Detail and Junction Objects)

 Here's a tabular comparison of the Lookup and Master-Detail relationship types in Salesforce:


FeatureLookup RelationshipMaster-Detail Relationship
Definition and UsageLoosely coupled; records are linked but can exist independentlyTightly coupled; child record depends on the parent for existence
Data Integrity and OwnershipChild record does not inherit parent’s sharing or ownershipChild inherits sharing, permissions, and ownership from the parent
Roll-up Summary FieldsNot availableAvailable; aggregates values from child to parent
Required FieldOptional; child can exist without a parentRequired; child must have a parent
Cascade DeleteOptional (not automatic)Automatic; deleting parent deletes all related child records
Security and AccessChild has independent sharing settingsChild inherits sharing settings from the parent
Hierarchy DepthFlexible; supports multi-level relationshipsLimited to strict parent-child hierarchy with up to two relationships

This structure provides a quick reference to understand when to use each relationship type based on your data needs in Salesforce.



-----


Does Master-Detail relationship always need a junction object ?
ChNo, a Master-Detail relationship does not always require a junction object
  • Standard Master-Detail Relationship: Often, a Master-Detail relationship exists directly between two objects, where one is the parent (master) and the other is the child (detail). For example, a custom "Invoice" object can have a Master-Detail relationship with a "Customer" object, where each invoice must be related to a customer.

  • Junction Objects for Many-to-Many Relationships: A junction object is specifically used when you need to create a many-to-many relationship between two objects. In Salesforce, direct many-to-many relationships aren’t supported natively, so you use a third custom object (junction object) with two Master-Detail relationships to the two other objects. This junction object lets records from two different objects relate to each other in a many-to-many manner.

Comments

Popular posts from this blog

API Names in Salesforce

18 - LWC - BEST PRACTICES - For accessing HTML elements and their values in JavaScript