Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

2- Data Modeling and Management – 12%

2.2 – Relationship Types

Copyright © Walid El Horr 1


Relationships
• A relationship is a two-way association between two objects.

• Without relationships, you could build out as many custom objects as you can think of, but they'd have no way of
linking to one another.

• With relationships, you can display data about other related object records on a particular record's detail page.

Copyright © Walid El Horr 2


Entity Relationship Model
One to One:

• Husband / Wife

• A Wife can have one husband only

• A Husband can have one Wife only

Copyright © Walid El Horr 3


Entity Relationship Model
One to Many:

• Team / Player

• A Player can have one Team only

• A Team can have many Players

Many to One:

• Player / Team

• A Team can have many Players

• A Player can have one Team only

Copyright © Walid El Horr 4


Entity Relationship Model
Many to Many:

• Subject / Student

• A Student can attend many Subjects

• A Subject can be attended by many Students

Copyright © Walid El Horr 5


Entity Relationship Model
Think and Guess the Entity Relationship types for the below Objects:

• Author / Book Author Book One-to-Many Parent / Child

• Publisher / Book Publisher Book One-to-Many Parent / Child

• Book / Review Book Review One-to-Many Parent / Child

• Book / Bookstore
Book Bookstore Many-to-Many

Copyright © Walid El Horr 6


Salesforce Relationship Fields
In Salesforce, we don’t deal with primary keys and foreign keys to
define relationships between data, but the Force.com platform uses
Relationship Fields.

There are 2 types of Relationship Field:

• Lookup: appropriate when a relationship between two objects is Opportunity is the child of Account
not tight,
Account is the Parent of Opportunity
• Master-Detail: appropriate when a relationship between two
objects is tight, Relationship Field is on the Child Object  on
Opportunity!
To relate 2 Objects via a One-to-Many Relationship, you should always
create the Relationship Field on the child Object (the “Many” side
Object).

Copyright © Walid El Horr 7


Salesforce Relationship Fields
Lookup Relationship: Master-Detail Relationship:

• This creates a relationship that links one object to another • This creates a relationship that links one object to another

object object

• Master-Detail field created on the Child Object (Detail)


• Lookup field created on the Child Object

• Related List created on the Parent Object (Master)


• Related List created on the Parent Object
• The 2 Objects are tightly related
• The 2 Objects are loosely related
• Ownership and sharing of detail records are determined by
• Ownership and sharing is independent the master record

• Record Deletion is independent • When you delete the master record, all of its detail records
are automatically deleted along with it
• Lookup fields can be optionally required on child records.
• Master-detail relationship fields are always required on detail
records.

Copyright © Walid El Horr 8


Many-to-Many
• A many-to-many relationship allows each record of one object to be linked to multiple records for another object
and vice versa

• To create Many-to-Many relationships, we can link Objects using a Junction Object

• A junction object is a custom object that is Child to both Objects via 2 Master-Detail relationships

• To create a many-to-many relationship, you first create the Junction Object, then create the 2 Master-Detail
relationships for it

Copyright © Walid El Horr 9


Relationship Fields
Think and Guess the Entity Relationship types for the below Objects:

• Author / Book Author Book

• Publisher / Book Publisher Book

• Book / Review Book Review

• Book / Bookstore
Book Bookstore Book Selling Bookstore

Copyright © Walid El Horr 10


Other types of Relationships
• Hierarchical: A special lookup relationship available for only the User object. It lets users use a lookup field to
associate one user with another that does not directly or indirectly refer to itself

• External Lookup:

• Links a child standard, custom, or external object to a parent external object.

• The standard External ID field on the parent external object is matched against the values of the child’s external lookup
relationship field.

• External object field values come from external data source

• Indirect Lookup

• links a child external object to a parent standard or custom object

Copyright © Walid El Horr 11


The “Books Cloud” App

Publisher

Review Book Author

Selling

Bookstore

12
The “Books Cloud” App

Object Child Of Relationship Field to Create


Book Author Lookup to Author
Publisher Lookup to Publisher
Author N/A
Publisher N/A
Review Book Master-Detail to Book
Bookstore N/A
Selling Book Master-Detail to Book
Bookstore Master-Detail to Bookstore

13
Summary
In this chapter, you have learned:

• Entity Relationship Model

• Relationship Fields in Salesforce

• How to establish relationships among Salesforce Objects

14
Relationship Types

Thanks for Watching! 

15

You might also like