Create Object Relationships | Trailhead Screen Reader Instructions


Learning Objectives

After completing this unit, you’ll be able to:


What Are Object Relationships?

Now that we’re comfortable with objects and fields, it’s time to take things to the next level with object relationships. Object relationships are a special field type that connects two objects together.

 

Let’s think about a standard object like Account. If a sales rep opens an account, they’ve probably been talking to a few people at that account’s company. They’ve probably made contacts like executives or IT managers and stored those contacts’ information in Salesforce.

It makes sense, then, that there should be a relationship between the Account object and the Contact object. And there is!

 

When you look at an account record in Salesforce, you can see that there’s a heading for contacts on the Related tab. You can also see that there’s a button that lets you quickly add a contact to an account.

An account record with two related contacts.

The Account to Contact relationship is an example of a standard relationship in Salesforce. But just like objects and fields, you can build custom relationships as well. In the last unit, you created two objects: Property and Offer. Wouldn’t it be great if all the offers made on a home showed up on its record in Salesforce?

Before we do that, let’s talk about the different kinds of relationships you can create in Salesforce.

 

The Wide World of Object Relationships

There are two main types of object relationships: lookup and master-detail.

 

Lookup Relationships

In our Account to Contact example above, the relationship between the two objects is a lookup relationship. A lookup relationship essentially links two objects together so that you can “look up” one object from the related items on another object.

Lookup relationships can be one-to-one or one-to-many. The Account to Contact relationship is one-to-many because a single account can have many related contacts. For our DreamHouse scenario, you could create a one-to-one relationship between the Property object and a Home Seller object.

 

Master-Detail Relationships

While lookup relationships are fairly casual, master-detail relationships are a bit tighter. In this type of relationship, one object is the master and another is the detail. The master object controls certain behaviors of the detail object, like who can view the detail’s data.

For example, let’s say the owner of a property wanted to take their home off the market. DreamHouse wouldn’t want to keep any offers made on that property. With a master-detail relationship between Property and Offer, you can delete the property and all its associated offers from your system.

A property with several related offers.

 

More on Relationships

Just like in real life, relationships are complicated. Here’s a bit more information to help you differentiate between lookup and master-detail relationships.

Typically, you use lookup relationships when objects are only related in some cases. Sometimes a contact is associated with a specific account, but sometimes it’s just a contact. Objects in lookup relationships usually work as stand-alone objects and have their own tabs in the user interface.

In a master-detail relationship, the detail object doesn’t work as a stand-alone. It’s highly dependent on the master. In fact, if a record on the master object is deleted, all its related detail records are deleted as well. When you’re creating master-detail relationships, you always create the relationship field on the detail object.

 

Finally, you could run into a third relationship type called a hierarchical relationship. Hierarchical relationships are a special type of lookup relationship. The main difference between the two is that hierarchical relationships are only available on the User object. You can use them for things like creating management chains between users.

 

When you start adding relationships between objects, remember that you’re increasing the complexity of your data model. That’s not a bad thing, but be extra cautious when you do things like change and delete objects, records, or fields. Check out the resources section for more information on relationship behaviors.


Create a Custom Object

We’re ready to jump back in with D’Angelo to build some relationships for the DreamHouse app. Let’s say DreamHouse wanted a way to track users who mark particular properties as favorites on their website. This feature can help DreamHouse’s real estate brokers reach out to potential home buyers.

Even if you're completing this module as part of the Admin Beginner trail, be sure you use the new Trailhead Playground you created in the previous unit.

To start, create a custom object called Favorite and add a field to the object.

  1. From Setup, select the Object Manager tab.
  2. Press ENTER on the Create button and select Custom Object from the menu.
  3. For Label, enter Favorite.
  4. For Plural Label, enter Favorites.
  5. Check the box for Launch New Custom Tab Wizard after saving this custom object.
  6. Leave the rest of the values as default and activate the Save button.
  7. On the New Custom Object Tab page, activate the Lookup (new window) link and select a style you like. This style will represent an icon visible in your navigation menu next to the object name.
  8. Press ENTER on the Next button, Next again on the following page, and Save on the final page.

 

Create a Lookup Relationship

We’re going to create two custom relationship fields on the Favorite object. First, let’s create a lookup relationship that lists the users who select Favorite for a property.

  1. From Setup, go to Object Manager  and select Favorite from the table of objects.
  2. In the right sidebar marked by the heading level 1, press ENTER on the Fields & Relationships tab.
  3. Activate the New Custom Field button.
  4. Choose Lookup Relationship  and activate the Next button.
  5. From the combo box labeled Related To, choose Contact from the list.

For the purposes of DreamHouse, contacts represent potential home buyers.

  1. Activate the Next button.
  2. For Field Name, enter Contact, then click Next.
  3. Activate the Next button on this page, then Next again on the following page, then the Save button on the following page.

 

Create a Master-Detail Relationship

Now, we’re going to create a second relationship field. We want a master-detail relationship where Property is the master and Favorite is the detail.

  1. On the Object Manager page for the custom object, press ENTER on the Fields & Relationships tab.
  2. Activate the New Custom Field button.
  3. Select Master-Detail Relationship and activate the Next button.
  4. From the Related To combo box, choose Property.
  5. Click Next.
  6. For Field Name, enter Property and activate the Next button.
  7. Press ENTER on Next, Next again on the following page, and Save on the final page.

Now, if you look at a Property record with the Related tab selected, you’ll see a related list for Favorites marked by a heading on the record page.


Add a Favorite Property

Let's take a look at how to view favorite properties.

  1. Activate the App Launcher button. Search for and select the result for Sales.
  2. Press ENTER on the Properties link in the navigation menu. If you don’t see it, activate the Show More button at the end of the navigation menu to view more options.
  3. Choose any Property record from the table.
  4. Under the first Tabs heading on the page, ensure the Related tab is selected. Navigate down the page by heading. You’ll see a heading called Favorites (0).
  5. Under that heading, activate the New button.
  6. Enter a name for Favorite Name, then activate the Save button.

Great job! Our Favorite object is all set up.

 

Resources


Where possible, we changed noninclusive terms to align with our company value of Equality.

This is a work in progress, so if you find a term to evaluate for inclusive language, return to the unit on Trailhead and click the Provide feedback for this badge link to submit it.

 


Click to return to the unit on Trailhead to access your challenge and proceed to the next step.