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
PRADEEP YADAV 5PRADEEP YADAV 5 

Delete those student records permanently from your salesforce org who have second letter ‘R’ in their names

List<Student__c>obj1 = [Select Name,Student_Name__c From Student__c  Where  Student_Name__c Like '_r%' And
                               isDeleted = true All Rows];
        Database.emptyRecycleBin(obj1);
Best Answer chosen by PRADEEP YADAV 5
SwethaSwetha (Salesforce Developers) 
HI Pradeep,

I tried something like this and it initially threw me the same error message you posted when there are no deleted records.

List<Account> a=[Select id,Name From Account Where Name Like '_r%' and isDeleted=true ALL ROWS];
system.debug(a+'===');
Database.emptyRecycleBin(a);
system.debug(a+'===');

However, after deleting a record that satisfied the SOQL condition , and running this same code in the dev console, it ran without error message showing the deleted record in system.debug.

I believe there were no records to be deleted from recyclebin which caused the error.Can you check the recycle bin and confirm?
 
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful.
 
Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Pradeep,
Can you share more details on your ask? Are you seeing any error? Thanks
PRADEEP YADAV 5PRADEEP YADAV 5
Yes Swetha 
 
SwethaSwetha (Salesforce Developers) 
HI Pradeep, Can you post the error message?
PRADEEP YADAV 5PRADEEP YADAV 5
System.UnexpectedException: MISSING_ARGUMENT: emptyRecycleBin called with a batch of 0 ids to delete; must specify at least 1 id
Subramanyam Kamath 4Subramanyam Kamath 4
Seems like SOQL is not generating any records. Can you add System.debug to the list & review if it is returning records?
SwethaSwetha (Salesforce Developers) 
HI Pradeep,

I tried something like this and it initially threw me the same error message you posted when there are no deleted records.

List<Account> a=[Select id,Name From Account Where Name Like '_r%' and isDeleted=true ALL ROWS];
system.debug(a+'===');
Database.emptyRecycleBin(a);
system.debug(a+'===');

However, after deleting a record that satisfied the SOQL condition , and running this same code in the dev console, it ran without error message showing the deleted record in system.debug.

I believe there were no records to be deleted from recyclebin which caused the error.Can you check the recycle bin and confirm?
 
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful.
 
Thank you
This was selected as the best answer
PRADEEP YADAV 5PRADEEP YADAV 5
Thanks Swetha