So far, you have defined a couple of Force Platform objects and created a productive link between them. The power of relationships drives data design on the Force Platform, and good development practices suggest that you spend time designing your objects to leverage the full productivity of these relationships. In this section, you will learn about a different tyype of relationships you can easily create in your Force Platform database.
The relationship you created in the previous section is known as a one-to-many relationship. Each Position record is associated with one Location record, and a Location record can be associated with many Position records.
But what about situations that call for a many-to-many relationship? In this type of relationship, a record on each side of the relationship can be associated with many records on the other side.
The Recruiting application you are building contains a good example of this type of relationship. Each Position record can be associated with many different Candidates, an object you will create shortly. And each different Candidate can apply for many different Positions.
In order to implement this type of relationship, you need to create an intermediate object, referred to as a junction object. This object has a relationship to the objects on both sides of the many-to-many relationship, with a single instance of this junction object for each relationship between an individual Candidate and an individual Position.
1. | Follow to the instructions in the Code Share project for this book, described in Chapter 1: Welcome to the Force Platform, to create the Candidate object and its fields. |
2. | Follow the instructions in the Code Share project for this book to create the Job Application object. |
The Job Application object is used to create a junction between a Candidate record and a Position record. You are now ready to implement a many-to-many relationship.
Your objects are in place, so you can now link the Position and Candidate objects through the Job Application object. As mentioned above, each Candidate can apply for more than one Position, and each Postion can have many different Candidates. The Job Application record links together a single Candidate for a single Position, as well as including other information.
1. | |||
2. | Add a new master-detail relationship field to this object, linking the Job Application object to the Position object. | ||
3. | Accept the default Field Label and Field Name, and give the field an appropriate description and help text. Note that the field is automatically set to required. You can limit access to this detail record based on the shared setting for the master record. You can either require users to have read and write access to the master record in order to create, edit, and delete this detail record, or you can only require read access to the master record. In this scenario, you probably want to require the more limited access. Note
| ||
4. | |||
5. | Accept the default security and page layout choices on the next two pages, clicking Save and New on the final page of the wizard. You want to have a master-detail relationship between the Job Application object and the Position object to be able to use Roll-up Summary Fields to aggregate information about the applications for the jobs. | ||
6. | Add a master-detail relationship from this object to the Candidate object, again including an appropriate description and help text, the more limited Sharing Setting as with the Positions relationship, and accepting the default security and page layout choices. Click Save. |
Although you will not have an immediate need to use Roll-up Summary Fields from the Job Application object to the Candidate object, the master-detail relationship is still appropriate here because of the way you want the Candidate and Job Application records to interact. For the purposes of this system, you will want to delete all individual Job Application records once either the Candidate record is deleted or the Position is deleted. The Job Application record is not meaningful if either side of the many-to-many relationship is no long available.
The order in which you define the two master-detail relationships has an effect on the representation of this object in the Force Platform environment. When displaying links to a record in the Job Application object, the icon used is the icon associated with the tab of the first master-detail relationship defined for this object.
With these two steps, you have implemented a many-to-many relationship. You can add more information to this object, such as status indicators that apply to individual Job Applications, rather than an Candidate or Position – an action you will take in the next chapter.
At this time, there is no need to define a tab for Job Application since you will be able to create new Job Application records directly from either the Position or Candidate pages.
Your recruiting application now has the ability to define and use many-to-many relationships. You did not load any data into the Job Application object you defined, so you can see how this object works behind the scenes to implement the relationship.
Relationships, and the functionality they provide, are one of the core pieces powering the productivity of the Force Platform. Understanding the relationships inherent in your overall data scheme helps you create more flexible applications with cleaner implementations.
3.141.19.185