All Collections
Data Backup
Restoration
Restoring deleted records with dependent objects
Restoring deleted records with dependent objects

Restoring records and their associated deleted child records

Alex Walter avatar
Written by Alex Walter
Updated over a week ago

Gearset has a workflow to allow you to restore deleted records and any related child records that were removed as a result of that deletion. This workflow will allow you to build up a restore plan starting with a base object, and then you can select the records of child objects (and grandchild / child-of-child objects) you want to restore.

A common example of this would be an Account record that was deleted. The cascading nature of the Salesforce's deletion logic means that all the Opportunities on the Account and the OpportunityLineItems (listed as Products on the Opportunity) will also be deleted. The new restore flow will allow you to restore all of these items in a single restoration deployment.

How to use the workflow

The new workflow can be accessed through View changes via the restore button in the changes details page. This will only appear for records where you have deleted/changed records in this run.

Click Restore and select Restore records with dependent objects.

Restoring objects with dependencies

Clicking this button will select this object as the Base object where we can build up a restoration plan. When you come into the Restore from [Base object] page, we will show the Base object along with the first level of child relationships.

If you expand the relationship it will then populate with the next level of relationships:

Note that by default we only show objects with non-zero counts of records. If you want to see the relationships where there are no unchanged records, you can click the Show unchanged records button:

As there can be many relationships which do not have any unchanged records, we hide these by default, but it can be useful to check to confirm that no related records were deleted along with the Base object records.

You are also able to filter on the Base object, by clicking the filter icon in the Total records to restore column:

This will bring up a similar filter dialog to those used in data deployments or browsing backed up records:

Once you apply this filter to the Base Object it will also update the record counts for the related child objects:

You can check which records have been filtered by clicking on the PREVIEW RECORDS button.

This will give you an overview of the records that you are going to restore as well as detailed information about each one:

Once you have selected the records you want to include, you can select whether you want the deployment to continue if steps encounter an error. Once you have made this selection, you can create a restore plan by clicking the continue button:

This will run the data problem analyzer to find any potential failures for this deployment. More information on these problem analyzers can be found here.

When the problem analyzers have finished running, then Gearset will automatically start a metadata comparison to find any active flows, triggers or validation rules on the objects to be restored, it is recommended you disable these before the deployment as these may cause Salesforce deployment errors. This can be done either manually in your Salesforce org, or through Gearset. To disable these through Gearset, select what needs disabling and then select Start deactivation deployment before continuing.

(Note: these will not include manage package metadata triggers or validation rules.)

Once you've finished your restoration, you can re-enable the rules, triggers and flows by rolling back the metadata deployment via the deployment history in metadata deployments.

Finishing the restoration

Once the restoration plan is created, you will be brought to the backup data summary page, similar to what you would see on the final stage of a restore:

To view the records about to be deployed for an object, click on the name of the object being deployed (for example Account).

Click Deploy data to deploy to restore back to your org:

Your records should now have been restored to your org.

Notes:

  • We do not support restoring children of the same object type: e.g. Child Accounts, we are looking to add this functionality in at a later stage

Example: Restoring a deleted Account along with its Opportunities and OpportunityLineItems

We will now walk through an example of how you can restore a fairly simple deletion using this new workflow. The example we use is for the deleted records of some standard Salesforce objects: Account, Opportunity and OpportunityLineItem. Note: This workflow also works for most object and their child relationships, see below.

The relationship here is Account has child Opportunities; Opportunities have child OpportunityLineItems. Viewing this on the Schema builder in Salesforce (OpportunityLineItems are shown as Opportunity Products):

In a simpler form, where the arrows point from a parent record to a child record:

Here is an example in Salesforce:
We have an Account with two Opportunities on it:

One Opportunity has 3 OpportunityLineItems (shown as Products):

Another Opportunity has 4 OpportunityLineItems (shown as Products):

This Account then gets deleted. On the next data backup run, we see that we have the deleted Account along with its 2 Opportunities and 7 OpportunityLineItems. We select Restore records with dependent objects with dependencies, using the deleted Account as the Base object.

When we open the Restore from Account page, the Child relationships are populated. We can see the Account object has Opportunities as a child:

We then expand the Opportunities to get the OpportunityLineItems:

We can now double-check that those are the correct records by hitting the PREVIEW RECORDS button:

Here we can see all the Opportunity records that are going to be restored:

We then select the Account, Opportunity and OpportunityLineItems and click Preview restore to plan a restoration:

Once that has been selected, Gearset will begin the problem analysis of the data deployment. Read more about it here.

When the problem analyzers have finished running, then Gearset will automatically start a metadata comparison to find any active flows, triggers or validation rules on the objects to be restored, it is recommended you disable these before the deployment as these may cause Salesforce deployment errors. This can be done either manually in your Salesforce org, or through Gearset. To disable these through Gearset, select what needs disabling and then select Start deactivation deployment before continuing.

(Note: these will not include manage package metadata triggers or validation rules.)

This will create a plan where we can deploy the data:

We then click Deploy data to restore the data:

Once it has completed we can view the restored records in Salesforce:

Restoring with a custom setup

Even though the example above is for standard Salesforce objects, similarly, you can restore this way for many different setups. For example the same process could be used for an org with custom objects with child and grandchild relationships:

Future plans and feedback

We are always looking to improve the product and want to work on features that offer the most value to customers. If you have any feedback of how we can improve this workflow or new functionality we can add let us know through the in-app chat. We look forward to hearing from you!

Did this answer your question?