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
objectArecord, because it needs a reference to an existingobjectBrecordit can't create an
objectBrecord, because it needs a reference to an existingobjectCrecordit can't create an
objectCrecord, because it needs a reference to an existingobjectArecord
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.
In Salesforce Setup, search for
Schema Builderin the Quick Find box and open it.Select
Clear Allin the objects panel, then add only the objects included in your data deployment. This keeps the diagram focused on the objects that matter.In
View Options, turn onShow Relationshipsso 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.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.
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.For each field in that loop, open it (either from the schema diagram or from
Object Manager> the object >Fields & Relationships) and check whetherRequiredis 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.
