中文口语版:
“Salesforce 主要有三种对象关系:Lookup、主从(Master-Detail)和Junction。
Lookup是松散关系,子记录可独立存在;
主从是紧密关系,子记录依附主对象,继承共享与安全;
多对多场景下,我们会用Junction,通过两个主从关系实现多对多”
“Salesforce supports three main relationship types — Lookup, Master-Detail, and Junction.
Lookup is a loose relationship — the child can exist independently.
Master-Detail is tighter — the child inherits ownership and sharing from the parent.
And for many-to-many relationships, we use a Junction Object with two Master-Detail fields to connect two parents.”
| Type / 类型 | Example / 示例 | Rule / 特性 | 中文总结 |
|---|---|---|---|
| Master-Detail (1 : n) | Opportunity → Line Item | Child depends on parent | 子依附主对象,继承共享与安全 |
| Lookup (1 : n) | Account → Contact | Optional link | 松散连接,可独立存在 |
| Junction (n : n) | OpportunityContactRole | Two Master-Detail fields | 通过两个主从关系实现多对多 |
| Type / 类型 | Description (English / 中文说明) |
|---|---|
| Lookup Relationship (1 : n) | Loosely links two objects. The child can exist independently even if the parent is deleted. 👉 查找关系是松散连接,子对象可独立存在,即使父对象被删除也不会受影响。 |
| Master-Detail Relationship (1 : n) | Tightly binds parent and child. The child inherits ownership, sharing, and security settings from the parent. 👉 主从关系是紧密绑定,子对象依附主对象并继承所有权与共享规则。 |
| Junction Object (n : n) | A custom object with two Master-Detail relationships, allowing a many-to-many connection between two parents. 👉 连接对象通过两个主从字段把两个主对象连接起来,实现多对多关系。 |
| Feature / 特性 | Master-Detail (主从关系) | Lookup (查找关系) |
|---|---|---|
| Data Dependency / 数据依赖 | 🔒 The child cannot exist without its master record.👉 子记录必须依附主记录存在,若主记录被删除,子记录也会被删除。 | 🔓 The child can exist independently from the parent.👉 子记录可以独立存在,即使父记录被删除也不会受影响。 |
| Deletion Behavior / 删除行为 | Deleting the master automatically deletes all child records (cascade delete).👉 删除主记录时,系统会级联删除所有子记录。 | Deleting the parent does not affect the child.👉 删除父记录不会影响子记录,子记录仍会保留。 |
| Ownership / 所有权 | Child inherits owner and record access from master.👉 子记录继承主记录的所有者与访问权限。 | Each record has its own owner and access settings.👉 父子对象各自拥有独立的所有者与访问权限。 |
| Sharing & Security / 共享与安全 | Child record follows the master’s sharing rules.👉 子对象的共享规则与主对象一致,不可单独设置。 | Child record’s sharing and security are independent.👉 子对象可单独配置共享与访问权限。 |
| Roll-up Summary / 汇总字段 | ✅ Supported. You can create Roll-Up Summary fields on the master object to summarize child data (e.g., COUNT, SUM).👉 主对象可创建汇总字段来统计子对象数据。 | ❌ Not supported. Roll-Up Summary fields are unavailable for Lookup relationships.👉 查找关系不支持汇总字段功能。 |
| Reparenting / 改变父记录 | Optional — controlled by “Allow reparenting” setting.👉 是否允许子记录更换父对象需在设置中勾选“Allow reparenting”。 | Always allowed — child can freely change parent record.👉 查找关系默认可更换父记录,无需额外设置。 |
| Cascade Behavior / 级联行为 | Cascades owner, sharing, and delete operations from master to detail.👉 主从关系支持所有权、共享、删除的级联传递。 | No cascade — actions are independent between parent and child.👉 查找关系操作互不影响,无级联。 |
| Use Case / 适用场景 | Strong dependency between objects.Example: Opportunity → OpportunityLineItem (Order Items depend on Opportunity).👉 适用于强依赖场景(如机会与产品项),子对象依附主对象存在。 | Loose association or optional link.Example: Account → Contact (Contact belongs to Account but can exist alone).👉 适用于弱关联或可选场景(如联系人属于客户,但可独立存在)。 |
📘 Concept / 概念:
Salesforce doesn’t directly support many-to-many relationships.
Instead, we create a Junction Object that connects two parent objects via two Master-Detail fields.
Salesforce 不直接支持多对多关系,需要通过一个「中间对象(Junction Object)」
使用两个主从关系来间接实现。
📊 Example / 示例: