DML Delete
The DML Delete feature provides a powerful way to bulk delete Salesforce records using SQL-like syntax. It supports both soft deletes (which can be undeleted later) and hard deletes (permanent removal). This feature includes comprehensive safety mechanisms to prevent accidental data loss.
This page covers only things specific to DML Delete operation so please refer to DML Update page to
understand how DML operations work in general, how to execute them, and view the results.
DML Delete Syntax
DML Delete statements follow this syntax pattern:
DELETE [HARD] [MAX <max_records>] [FROM] <SObject>
[USING SCOPE <scope>]
[WHERE <conditions>]
[ORDER BY <field> ASC|DESC]
[LIMIT <number>]
[OFFSET <number>]
- The optional
MAXclause acts as a safety mechanism to prevent accidentally deleting too many records. If you specify that clause with a count, then the app will error the operation if the query matches more records than that count.
Delete Types
Soft Delete (Default)
DELETE Account
WHERE Type = 'Prospect' AND CreatedDate < LAST_YEAR
Soft delete moves records to the Recycle Bin where they can be restored. This is the default and recommended approach for most scenarios.
While Soft Delete moves the records to the Recycle Bin, it is not guaranteed to be recoverable. It depends on how many records you’re deleting, type of object etc., So it is always a good idea to back up critical data before performing deletes.
Hard Delete
DELETE HARD Test_Data__c
WHERE CreatedDate < LAST_MONTH
Hard deleted records CANNOT be recovered! Make sure you have a back up of the data as necessary.
Delete Examples
Delete by Status
DELETE Lead
WHERE Status = 'Unqualified'
AND CreatedDate < LAST_90_DAYS
Delete with Relationship Criteria
DELETE Contact
WHERE Account.Type = 'Prospect'
AND LastActivityDate < LAST_6_MONTHS
Delete Using Complex Conditions
DELETE from Case
WHERE Status = 'Closed'
AND CreatedDate < LAST_YEAR
AND Priority IN ('Low', 'Medium')
Related Features
- DML Update: Bulk update records
- DML Undelete: Restore soft-deleted records
- Edit Data: Interactive record editing
- Export Records: Backup data before deletion
- Recycle Bin Management: Salesforce standard recovery tools