relationships in salesforce
relationships in salesforce
Data relationships between objects in Salesforce can be a tricky topic to get your
head around. You may be faced with a business scenario that requires creating a
custom object. Then, the next decision is which relationship types you should use to
extend your Salesforce data model.
This is a fundamental concept to learn, as it ensures that you pick the right
relationship type that ensures a scalable data model.
1. Lookup Relationships
The lookup is a loosely coupled relationship, allowing you to connect one object to
another in a one-to-many fashion.
In this example, you can see that an asset may be involved with a number of cases –
if the case is deleted, the asset will remain and vice versa.
Master-detail also allows the parent record to control child record attributes, such as
sharing and visibility. The child record inherits whichever security setting you choose
for the parent record.
In this example, you have a list of rooms employees can book for meetings. If the
room is deleted, what use would the meetings be? None! However, when creating a
master-detail relationship, you can check a box to allow reparenting – you could be
kind and allow them to select a new room!
The sweet spot with master-detail relationships is that you can create roll-up
summary fields! Note that a single object can have a maximum of two master-detail
relationships.
One more example:
Lookup Fields:
3. Many-to-Many Relationships
Say you have a situation where it is required you have many of one record related to
many of another. Duplicating the lookup field a number of times on each object
is not the best practice and will get very messy. This is where we should
leverage Junction Objects.
In the image below, we see that a session can have multiple speakers – but
speakers can also present at multiple sessions. Adding the “Session Speaker”
Junction Object in between is a perfect place to handle this relationship!
4. Self Relationship
Let’s say you have a campaign that is a part of a bigger campaign. You can use a
lookup field from campaign to… campaign! But why? This would be a great situation
to show how multiple child campaigns relate to the main parent campaign (known as
a Campaign Hierarchy).
5. External Relationships
There are two more types of lookups for working with external objects that we should
cover briefly:
Indirect lookup relationships: These allow a relationship to be formed between a Salesforce object and an external object.
If your Salesforce org was the family, then the objects would be related but not in the same family. A great example is
relating payment records to an account from an ERP system – the ERP system is external to Salesforce, but the records are
important. They relate via an external ID to match the payments to the account.
External lookup relationships: These allow a relationship to be formed between two external objects. Your two friends from
outside your group are now in a relationship. Maybe that ERP system links the payment records to a bank account.
6. Hierarchical Relationships
The hierarchical relationship is a simple but commonly forgotten relationship in
Salesforce. This unique relationship can only be used on the user object, and is
designed to create a hierarchy of users. For example, it could be used to create a
lookup field for the user object, which can then be used to list the user’s manager.