DeleteSource operation.
Table of Contents
Overview ⇧
Purpose: This feature enables the deletion of records directly from the source Salesforce organization, based on a complex selection derived from the entire export.json
configuration and considering the relationships between objects.
Feature Description ⇧
Unlike the standard Delete operation that targets records in the destination organization, the DeleteSource operation removes records from the source organization itself. This is particularly useful in scenarios where the data model involves complex relationships and direct SOQL query selection is insufficient or impractical.
For instance, you may need to delete Contacts related to specific Accounts, which in turn are linked to another object (e.g., Test__c). The DeleteSource operation handles such complex hierarchical data deletions by first retrieving all records for all objects configured in the export.json
, processing their relationships, and then executing deletions.
This operation is ideal if there is no separate target organization and you need to cleanse or manage data within a single org.
Example of DeleteSource Configuration ⇧
Here’s how you might configure the DeleteSource
operation:
"objects": [
{
"operation": "Readonly",
"externalId": "Name",
"master": true,
"query": "SELECT Id FROM Account WHERE Name LIKE 'Test%'"
},
{
"operation": "DeleteSource",
"master": false,
"query": "SELECT Id, Account__c FROM TestObject__c"
}
]
This configuration is set to delete TestObject__c
records that are associated with the selected Accounts based on the query conditions.
CAUTION: THIS OPERATION PERMANENTLY DELETES RECORDS FROM THE SOURCE ORGANIZATION. PLEASE PROCEED WITH CARE.
Notes
- When using DeleteSource, you only need to define the
--sourceusername
flag. - You cannot use a CSV file as the deletion source with the DeleteSource operation.
- It is possible to mix operations within the configuration; for instance, you can set DeleteSource for one object and other operations like Upsert for others. If doing so, include the
--targetusername
in your CLI command as necessary.
Executing the Deletion ⇧
Below is an example of a CLI command to execute a deletion from the source organization:
sfdx sfdmu:run --sourceusername delete-it@testorg.com