Sub topic 1
Relationships Connect Objects: Parents, Children, and Relationship Fields
Prerequisites
You should know Salesforce objects, fields, records, and basic SOQL SELECT syntax. You should also be familiar with Setup and Object Manager.
Relationship Fields and Parent-Child Terms
A relationship field connects one object to another. The object containing the field is the child. The referenced object is the parent. For example, a Contact can contain an Account relationship field. The Account is the parent of the Contact.
The relationship type determines whether the link is optional, whether the child depends on the parent, and what happens when records change.
Lookup Relationships: Loose, Optional Links
A lookup relationship is a flexible link between two objects. The lookup field can usually be left empty, so a child record can exist without a parent. The child and parent have separate ownership and sharing behavior.
For example, a Contact can exist without an Account. Deleting the Account does not generally delete the Contact. Use a lookup when the records are related but can live independently.
Restricting Lookup Choices with Lookup Filters
A lookup filter limits which parent records users can select. It can use fields on the parent, fields on the child, or fixed values.
For example, an Opportunity lookup might allow only Accounts where IsActive__c is true. A filter reduces incorrect selections, but it does not replace validation for every way records can be created or updated.
Master-Detail Relationships: Tightly Coupled Records
A master-detail relationship tightly couples a detail record to its master. The detail must have a master, so the relationship field is required. The detail inherits ownership and sharing from the master.
Deleting the master cascades to its detail records. In other words, Salesforce deletes the related detail records as part of deleting the master. Master-detail relationships also support roll-up summary fields on the master, such as counting detail records or totaling a numeric field.
Use master-detail when the child has no useful independent existence. For example, an Enrollment__c record may require both a course and a student when it represents participation in a course.
Exercise
Which relationship should you choose when a child record must always have a parent and should be deleted with that parent?
Show answer
Choose a master-detail relationship.