官术网_书友最值得收藏!

Creating relationships

In our movie example, we have our Movie object and we have our Person object. To create a many-to-many relationship between both, we need a junction object. As I mentioned previously, we will be using Cast as a junction object. So, let's create that junction object and see why we did that:

  1. Navigate to Setup | Object Manager.
  2. Create a new custom object with the following details:
    • Label: Cast
    • Plural: Cast
    • Record Name: Role Name
    • Type: Text
    • Allow Search: true
    • Leave the other defaults as is
  3. Now, create a new custom field:
    • Type: Master-Detail Relationship
    • Related to: MOVIE
    • Label: Movie
    • Field Name: Movie
    • Child Relationship Name: Cast
    • Leave all other defaults and click next, next, save
  4. Create the second custom field with following details:
    • Type: Master-Detail Relationship
    • Related to: PERSON
    • Label: Person
    • Field Name: Person
    • Child Relationship Name: Cast
    • Leave all other defaults and click next, next, save

Okay, now that we are able to link people with movies and movies with people, let's create a record in our database. Go to the The Godfather movie record that we created earlier. You'll be on the Details tab, but for that we have to add a record to the related list, Cast (which was added automatically by creating the relationship fields). So, click the Related tab and click New in the related Cast list. Fill in Michael Corleone as Role Name. Because we are creating a Cast record from the Movie record, the Movie lookup is already pre-populated with The Godfather. Now, click the lookup icon next to the Person field, select Al Pacino, and click Save (as illustrated in the following screenshot):

You have successfully added Al Pacino (the Person), to the Cast of The Godfather (our Movie) in the role of Michael Corleone! Now, do yourself a favor and navigate to our Al Pacino record and check out the Related tab there. You will find the same related Cast list and also the record for Michael Corleone played by Al Pacino in the movie The Godfather. I hope this example gives you a clear view on how a many-to-many relationship work.

Understanding the different relationship types and when and how to use them is a very important part of the Platform Developer I exam. So, make sure that you fully understand this. Feel free to create your own custom objects in your Developer Org and create multiple relationships to practice some more.

We will do the same in the next section, because, as you can see, we are not done yet! We'll be adding some extra relationships, but through Schema Builder instead of just through the Object Manager. Yep, I'm building up towards something here; no joke.

主站蜘蛛池模板: 开封县| 永登县| 七台河市| 台安县| 宝坻区| 宁陕县| 长垣县| 驻马店市| 砀山县| 呈贡县| 邵武市| 临潭县| 浦县| 邳州市| 西盟| 淮南市| 台北县| 镇平县| 精河县| 嘉兴市| 阿勒泰市| 宜章县| 澄城县| 肃宁县| 漯河市| 武平县| 二连浩特市| 股票| 饶河县| 上高县| 南木林县| 稷山县| 乌什县| 和政县| 阿拉尔市| 东阳市| 凤阳县| 延安市| 旬邑县| 澎湖县| 嘉义市|