Loading
Salesforce now sends email only from verified domains. Read More

Use Schema Builder to identify and query object relationship fields for delete performance

Publish Date: May 9, 2024
Description

Trying to identify child or detail records that may exist in relation to another record may seem like a daunting and manual task that requires reviewing each and every object in Salesforce for relationship fields however, this is not so with Schema Builder!

You can graphically view, identify, and document all relationships to and from a specific object to then build queries to identify where related records exist.

This is particularly helpful when you need to identify the cause of poor record deletion performance or occurrences of 'Delete Operation Too Large' messages.

See Work with Schema Builder for more information on getting started.

 

Resolution
Warning
Always back up your data before performing any data operation. See Export Backup Data from Salesforce or Export Data for more details. It is recommended to run a test with a small subset of records to ensure the operation was successful through manually opening and verifying that the corresponding records are correct in Salesforce.


Find related objects in Schema Builder:

 

1. Type your affected record's object name in the schema builder's 'Quick Find..' search box. Ensure the result returned in the section below is checked so it's visible then hover over the entry in the results and you should see a magnifying glass appear to easily locate your object on the canvas.

2. Once you have located your object, clear its name from the 'Quick Find...' so you can see the entire list of all objects and then click the 'Select All' link to expose all Salesforce objects in the builder. Click, hold, and drag your object to its own blank space on the canvas so you can easily view all of the object relationship lines.

Note: Relationship lines may overlap each other so it's recommended to manipulate the view by moving the object around on the canvas to ensure you can see all relationship lines from the object in question to all others.

3. Once you have a good view of the relationships hover your mouse over each line and copy down the object relationship information provided to identify all of the corresponding lookup or master-detail relationships pointing from other objects to the affected record's object.
 

Locate and document API Names for related objects and reference fields:

 
1. Locate related objects in setup and gather the following details in order to build your SOQL queries.

A) Object API name (the objects that are related to the affected record's object):

- Standard object's API names typically match their labels. For example, the Account object's API name is Account. For a list of standard objects see the Standard Objects | Object Reference for Salesforce and Lightning Platform documentation.

- Custom object's API names can be found by navigating to setup:

In Classic, enter "Objects" in the Quick Find box, then select Objects under the Create menu tree. Locate your object from the list and click its Label to open its detail page and copy the value in the 'API Name' field. 

In Lightning, open Object Manager and perform a 'Quick Find' search to locate the object and copy the corresponding value from the API NAME column.

2. Review each object from the prior step in setup to identify the relationship field(s) or the fields that are 'looking up' to the affected record's object to gather their API Names.

Refer to Find the API name of a field for more details on how to identify API names.

 

Create your SOQL queries:


Use the following example as a template to construct queries to return the Ids of the records that are related to the affected record (child side in a lookup field or detail in a master-detail field):

SELECT Id FROM <ObjectAPINameHere> WHERE <RelationshipFieldAPINameHere> = '<AffectedRecordIdHere>'

Replace:
<ObjectAPINameHere> with the related object's API name from step 1. above.
<RelationshipFieldAPINameHere> with the relationship field's API Name from step 2. above.
<AffectedRecordIdHere> with the Id of the record that you're experiencing the issue with when trying to delete.

Use the queries you have constructed and a client tool of your choice such as Data Loader, to perform an export or query as outlined in the Export Data documentation.

If a large number of rows or records (several thousand to 10,000+) are returned from your queries and/or exports, it's likely that this related data may be causing or contributing to your delete or data skew performance issue.

If a large amount of relational data is found, use the resulting export files to then perform a delete operation to mass delete the child records. See Insert, Update, or Delete Data Using Data Loader for more details on deleting data.

After the relational data has been deleted follow the steps in the 'After deleting the affected record's related records' section of the Error 'Delete Operation Too Large' or too slow when you delete records article to empty your organizations recycle bin and request a physical delete to purge relational data.


Additional Resources

Visualize Your Data Model Using Schema Builder

 

Knowledge Article Number

000382594

 
Loading
Salesforce Help | Article