Record relationships

A relationship is formed by a Lookup field being created from one object to another, often referred to as a parent and child relationship. There are two types of relationships in Salesforce: Master-Detail and Lookup.

Custom Metadata Type objects only support lookup relationships to other Custom Metadata Type objects or other Custom Object or Custom Field metadata. Some features described in this section only apply to Custom Objects, such as lookup filters and referential integrity. Custom Setting objects do not support any form of record relationships.

In some aspects, these types of relationships share similarities in how they are referenced when using SOQL and Apex and how they are input through the user interface (such as lookup filters described in the previous chapter). However, there are different limits depending on the referential integrity features that you use. You should keep these in mind when defining your own object model within your package, as well as considering what your customers may also add as part of their customizations, since the limits are shared. These considerations are as follows:

  • Utilizing the Master-Detail form of relationship provides a powerful way to model containment, where one parent object record acts as a container for other child records; in our example, a race contains Contestants:
    • The platform will automatically cascade delete the child records when the parent is deleted, and it will also enforce the need for a parent reference when the child records are created.
    • By default, the platform prevents users from moving the child records to another parent by editing the relationship field. However, you can disable this validation and permit this by selecting the Child records can be reparented to other parent records after they are created option.
    • With the use of Rollup Summary fields, it also becomes possible to build calculated fields based on values of the child record fields.
    • Salesforce, however, does recommend that this kind of parent-child relationship does not exceed 10,000 child records; otherwise, the platform will not support the cascade delete of child records.
    • You can define up to three levels of Master-Detail relationships.
  • Utilizing the Lookup type of relationship allows you to model connections between related records that are optional and may also have other relationships not necessarily in an ownership or containment relationship to their parents. Keep in mind the following points when using Lookup fields to define relationships:
    • Deletion of parent records will not result in a cascade delete of related child records; this can be enabled via Salesforce Support, though this setting will not be packaged.
    • Unlike with Master-Detail, you can elect for the platform to enforce referential integrity during the creation of the field by utilizing the Don't allow deletion of the lookup record that's part of a lookup relationship option.
    • Currently, the Rollup Summary fields are not supported when using a lookup relationship.

Lookup fields of either kind are automatically indexed by the platform, making queries, in some cases, faster. We will focus more on indexes in Chapter 11Asynchronous Processing and Big Data Volumes. The maximum number of relationship fields per object is 40.

While it is possible to add new Custom Fields to objects that have already been packaged and released to your customers, you cannot add a new Master-Detail relationship to an object that has already been packaged.

Record relationships are a key feature of defining your application's object model. This section has highlighted some areas you should consider carefully, as some may have future restrictions on your application and your customer's ability to customize it. A key aspect of the Lightning Platform is the existing objects it contains. The following section shares some considerations to keep in mind when leveraging Salesforce Standard Objects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.183.89