function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SidharthSidharth 

Hard Delete Records Options ?

What different ways can we hard delete salesforce records.

1. From within Apex (batch) ?
2. Bulk API (Java) ? 
3. Data loader - Hard Delete options ? Tried this, working fine.

Out requirements is to have a batch running every X minutes (inside/outide of SF) which can query records and hard delete them.

-Sid
Hargobind_SinghHargobind_Singh
Apex: 
1. Delete your record using Standard DML for delete: 
Database.DeleteResult[] delete(SObject[] recordsToDelete, Boolean opt_allOrNone)

2. Empty recycle bin for the records you have just deleted using : 
Database.EmptyRecycleBinResult[] emptyRecycleBin(ID [] recordIds)

API 
1. Delete your record using Standard DML for delete: 
DeleteResult[] = connection.delete(ID[] ids);

2. Empty recycle bin for the records you have just deleted using : 
EmptyRecycleBinResult[] = connection.emptyRecycleBin(ID[] ids);

 
Dhriti MoulickDhriti Moulick
Hi Sidharth,

    Best options in CRM is to
    1.create a batch class.
    2.apply your business logic(Hard Delete).
    3.Create schedule class.
SidharthSidharth
Hard Delete from within Apex, will require deleting the records, and emptying the recyclin bin ? No direct way to hard delete the records, right ?
sunny522sunny522
Hi Sidharth,
 Yes Sidharth...we donot have any direct DML operation in apex for hard delete.We should first delete the records and then empty recycle bin.
Please go through the link https://help.salesforce.com/articleView?id=000135460&type=1