Understanding Object Relationships and Junction Objects in Salesforce

Aashi GargAashi Garg
3 min read

In the vast universe of Salesforce, relationships aren’t just about connections; they’re the glue that holds your data together. Object Relationships are special field types that are used to establish a connection between two objects. There are primarily two types of relationships.

Lookup Relationship

A lookup relationship links two objects together, enabling you to access associated records easily. Lemme elaborate on it using an example. In a custom object “Employee,” you can establish a lookup relationship with the “Account” object, where each employee is associated with an account (company).

Master-Detail Relationship

In contrast, a master-detail relationship establishes a stronger link between two objects, where the child object is dependent on the parent object. Deleting the parent record will also delete the child records. This relationship is ideal for scenarios where you need a cascading effect, such as in invoice and line item relationships.

How to create a lookup or master-detail relationship

To create a lookup or master-detail relationship in Salesforce:

  1. Go to Object Manager.

  2. Select the object where you want to create the relationship.

  3. Navigate to Fields & Relationships.

  4. Click New Field.

  5. Choose Lookup Relationship or Master-Detail Relationship.

  6. Select the Related Object.

  7. Complete the field properties and save.

Junction Objects

One parent object has numerous associated objects in a one-to-many relationship, as seen by the two relationships mentioned above. What happens if we wish to depict relationships between things that are many-to-many? As an illustration, suppose you have two custom objects called “Student” and “Course.” A course may have more than one student enrolled in it, and a student may choose more than one course. Junction Objects enter the picture at this point. A junction object named “Enrollment” can be created to connect students to courses, with each record representing a student’s enrollment in a course.

To implement this in Salesforce, we establish a master-detail relationship between the “Student” object and the “Enrollment” object, as well as between the “Course” object and the “Enrollment” object. This setup allows us to link students to courses through the “Enrollment” junction object.

Conclusion

Object relationships in Salesforce are the backbone of data modelling, enabling you to establish connections between different objects and create powerful applications. Lookup and master-detail relationships help you link one object to another, while junction objects allow you to handle many-to-many relationships effectively.

In our upcoming blogs, we’ll explore exciting topics such as flows for process automation, Salesforce’s security model, and advanced topics including Apex. Whether you’re new to Salesforce development or looking to expand your knowledge, these blogs will provide you with valuable insights and practical tips to enhance your Salesforce journey.

Stay tuned for upcoming blogs, and feel free to comment if there’s anything specific you’d like me to cover!

1
Subscribe to my newsletter

Read articles from Aashi Garg directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aashi Garg
Aashi Garg

I am a Software Engineer Intern at Aethereus