Part I – 4.How to Create Junction Object in Salesforce



A junction object is a custom object with two master-detail relationships, and it is the key to making a many-to-many relationship.Let us assume we are having HR’s recruiting app and now we are going to create a junction object called Job Posting.

A job posting fits into the space between positions and employment websites. One position can be posted many times, and one employment website can have many job postings, but a job posting always represents a single position on a single employment website.

In essence, the Job Posting object has a many-to-one relationship with both the Position and the Job Posting Site objects. Through those many-to-one relationships, you create a many-to-many relationship between the Position and Job Posting Site objects.

Create a Custom Junction Object
  1. From Setup, click Object Manager.
  2. Click Create, select Custom Object, and fill in the details.
    Field Value
    Label Job Posting
    Plural Label Job Postings
    Record Name Job Posting Number
    Data Type Auto Number
    Display Format JOBPOST-{0000}
    Starting Number 1
  3. Leave everything else as is, and click Save.
  4. Next, create the master-detail relationship between Job Posting and Position.
    1. While still viewing Job Posting in Object Manager, click Fields & Relationships, then New.
    2. Select Master-Detail Relationship as the Data Type.
    3. Click Next.
    4. For Related to, select Position.
    5. Click Next.
    6. For Field Label, enter Position.
    7. Click NextNextNext and Save & New.

Now fill in the details for a master-detail relationship between Job Posting and Job Posting Site.

  1. Select Master-Detail Relationship as the Data Type.
  2. Click Next.
  3. For Related to, select Job Posting Site.
  4. Click Next.
  5. For Field Label, enter Job Posting Site.
  6. Click NextNextNext and Save.
Modify the Page Layouts

Next, add fields to the Job Posting Site related list on the Position page layout.

  1. From Setup, click Object Manager.
  2. Click Position, then Page Layouts.
  3. Click Down arrow next to Position Layout and select Edit.
  4. Scroll down to the Job Postings related list, and click Wrench icon in the header to edit it.
  5. From the Available Fields section, select
    • Job Posting Site: Status
    • Job Posting Site: Technical Site
  6. Click Add.
  7. From the Selected Fields section, select Job Posting: Job Posting Number and click Remove.
  8. Click OK, then click Save.

Finally, add fields to the Position related list on the Job Posting Site page layout.

  1. From Setup, click Object Manager.
  2. Click Job Posting Site, then Page Layouts.
  3. Click Down arrownnext to Job Posting Site Layout and select Edit.
  4. Scroll down to the Job Postings related list and click Wrench icon in the header to edit it.
  5. From the Available Fields section, select
    • Position: Status
    • Position: Title
  6. Click Add.
  7. From the Selected Fields section, select Job Posting: Job Posting Number and click Remove.
  8. Click OK, then Save.

Now let’s test what you’ve just done by creating a Job Posting record.

  1. Click App Launcher iconto open the App Launcher, then click Recruiting.
  2. Click the Positions tab, then New, then enter the details of the new position.
    Field Value
    Title Super Sales Rep
    Department Sales
    Approval Status Approved
    Location US
    Job Description Sales rep to join the AW Computing team serving the eastern region of AMER
  3. Click Save.
  4. Click the Job Posting Sites tab, then New, and enter the details.
    Field Value
    Site Name Lots-O-Jobs
    Job Posting Site www.Lotsojobs.com
    Status Active
  5. Click Save.
  6. On the Job Posting Site record you just created, click the Related tab.
  7. On the Job Postings related list, click New. For Position, search for and select Super Sales Rep and click Save.

This training blog is much more useful to learn about junction object.