Skip to main content

Resolving data deployment errors: loops in required lookup fields

Find and fix a lookup loop that's stopping your data deployment from running

Written by David Martin

If your data deployment fails with an error about a reference loop or recursion depth, this article explains what's causing it, how to trace the loop yourself in Salesforce, and how to fix it.
​

What this error means

When you configure a data deployment, Gearset works out an order to insert records so that every lookup field resolves correctly. This fails when the objects you've selected form a loop of required lookup fields, leaving Gearset with no valid starting point.
​

In a simple case, the loop looks like this:

objectA -> objectB -> objectC -> objectA

Since every lookup in that chain is required, Gearset can't create a record for any of the three objects first:

  • it can't create an objectA record, because it needs a reference to an existing objectB record

  • it can't create an objectB record, because it needs a reference to an existing objectC record

  • it can't create an objectC record, because it needs a reference to an existing objectA record

With no object able to go first, the deployment has nowhere to start, and Gearset can't complete it.
​

Real loops are often bigger and less obvious than this three-object example. A loop can involve custom objects several layers deep, and it's easy to introduce one without realizing it, especially when you add a new object as a related object partway through configuring your deployment.
​

Finding the loop in Salesforce

Gearset's error tells you that a loop exists, but not exactly where it sits in your object list. The fastest way to pin it down is to look at the relationships directly in Salesforce, using Schema Builder.

  1. In Salesforce Setup, search for Schema Builder in the Quick Find box and open it.

  2. Select Clear All in the objects panel, then add only the objects included in your data deployment. This keeps the diagram focused on the objects that matter.

  3. In View Options, turn on Show Relationships so the connector lines between objects are visible. Lookup relationships appear as blue lines, and master-detail relationships appear as red lines. The circle end of each line sits on the parent side of the relationship.

  4. Starting from any object in your deployment, follow its lookup lines to the objects they point to, then follow those objects' lookup lines in turn.

  5. If following the lines eventually brings you back to the object you started from, you've found the loop, for example objectA -> objectB -> objectC -> objectA.

  6. For each field in that loop, open it (either from the schema diagram or from Object Manager > the object > Fields & Relationships) and check whether Required is ticked.

A loop only blocks a deployment when every lookup field in it is required. If even one field in the loop is optional, Gearset already has a starting point and won't hit this error.
​

Once you know which objects are in the loop and which fields are required, you're ready to fix it.
​

Fixing the loop

There are two ways to give Gearset a starting point.
​

Option 1: exclude one object from the deployment

Remove one of the looping objects from your data deployment configuration. With one fewer object in the chain, Gearset has somewhere to start.

Keep in mind that no records will point to the excluded object once the deployment finishes. Choose the object whose reference matters least to you, or one you're happy to populate separately afterwards.
​

Option 2: temporarily make one lookup optional

In Salesforce Setup, remove the Required flag from one field in the loop. Gearset can then create records for that object first, leave the field blank, and go back to fill in the reference once every record in the loop exists.

Set the field back to Required once the deployment completes.

Either option gives Gearset a place to begin, so it can insert every other record in the loop and then circle back to complete the references.

Did this answer your question?