-
Notifications
You must be signed in to change notification settings - Fork 2
HOW TO #4 – Mass (Hard) Delete Data
ubraig edited this page Jul 12, 2023
·
1 revision
The command to delete data is Remove-SfRecords
that will take a one-column .csv file with the record Ids of the records to be deleted.
For the following examples, we assume:
- An authentication token for the target org in $MyOrg as created by
Get-SfAuthToken
- A .csv file
LeadsToBeDeleted.csv
list of Lead Record Ids to be deleted, for example exported viasfextract $MyOrg Lead "SELECT Id FROM Lead" LeadsToBeDeleted.csv
- This implicitly means, that we can rely on the auto-creation of the .sdl mapping file which will consist of just one line in this case:
Id=Id
- For a 'Bulk API Hard Delete' operation, your user in the org has got the proper permissions set, e.g. as described in
A soft-delete operation means, the records will we kept in the recycle bin of your org for a while.
To delete a small number of records via SOAP API:
Remove-SfRecords $MyOrg Lead LeadsToBeDeleted.csv
Considerations:
- If you expect a large number of records to be deleted, you might consider using the Bulk API.
- If you want to hard-delete records, this will require Bulk API.
- If your delete operations affect only Leads, you may opt for Bulk Parallel operation for faster execution time.
- However, if your delete job implies cascading delete operations, you might need to consider serial execution. This might be the case in the following scenario:
- Deleting a large number of Leads that are assigned to at least one Campaign via CampaignMember record each.
- Deleting a Lead will then do a cascaded delete on the CampaignMember records.
- Each deletion of a CampaignMember record will, as it is master/detail to the Campaign, also update the Campaign.
- Means: Parallel execution of Leads in this case might cause record locking congestion on the Campaign record.
- If there is a lot of automation logic (Apex Triggers, Flows) involved, you might want to reduce batch size to address issues with governor limits.
Some examples:
-
Remove-SfRecords $MyOrg Lead LeadsToBeDeleted.csv -Bulk Parallel
standard soft-delete via Bulk API with default batch size of 2000 -
Remove-SfRecords $MyOrg Lead LeadsToBeDeleted.csv -Bulk SerialHardDelete
hard-delete via Bulk API in serial mode with default batch size of 2000 -
Remove-SfRecords $MyOrg Lead LeadsToBeDeleted.csv -Bulk SerialHardDelete -BatchSize 100
hard-delete via Bulk API in serial mode with a reduced batch size of 100