Q: What are the different ways we can relate objects within Salesforce?
First, if we haven’t already done so, let’s review what an object is.
In Salesforce we can create relationship fields of three types, Master-Detail, Lookup, and External Lookup.
A Master-Detail relationship links two objects together and gives one control over the other, so to speak. If you imagine a data model of an Invoice and an Invoice Line Item, you might understand that an Invoice Line Item is the detail in a Master-Detail relationship. Why does this make sense? Because you’d never create a line item without it having an invoice to reside in, so the Invoice object is essentially the parent of the line item.
Within the Master object of a Master-Detail relationship, you can create summary fields and roll-up summaries to be able to extract and summarize information from the detail records. In our example, we could create a roll-up summary of the subtotals of the invoice line items into a field called “Total” within the invoice record. This would help to automate our work – we wouldn’t have to manually add up those amounts to arrive at a total.
It’s important to note that deleting or undeleting the master record will accordingly delete or undelete the related detail records.
A Lookup relates two objects to each other directly. Unlike Master-Detail relationships, they don’t support any kind of roll-up or summary fields. You can also use a lookup to relate a record to another record of the same object, which sounds confusing but will make sense if we look at an example. Maybe we released a new beta product to some users, and we are asking them for feedback. If we store that feedback in a custom object we might want a way to relate two pieces of feedback that are very similar. If we provide a solution based on that feedback, we know that we can update both of the users which are related via a lookup.
Also unlike a Master-Detail relationship, deleting a record which looks up to another will have no effect on the related record. By default, the field value storing the record which has been deleted will simply be cleared.
This is similar to a standard Lookup, but relates a record as a child of a parent which resides outside of Salesforce, utilizing the External ID field of the parent. Since it’s ambiguous to discuss data which could come from an infinite number of alternate sources, we won’t discuss external lookups any further.
That’s all, cheers! Check out the other Conversations here.