4

In my developer sandbox the Apex logs count has exceeded beyond its limit and there are more than 1 lakh records created in it. I want to mass delete them, but not able to do so.

I am using the windows machine, and tried running the below commands to achieve the same.

sfdx force:data:soql:query -q "SELECT Id FROM ApexLog" -r "csv" | out-file -encoding utf8 out.csv
sfdx force:data:bulk:delete -s ApexLog -f out.csv

But I am receiving an error in the console saying

ERROR running force:data:bulk:delete:  InvalidBatch : Records not found

Can anybody please let me know what am I doing wrong, and whether this can be achieved by any other ways.

7
  • I run the query you have listed via the Salesforce Developer Console's "Query Editor" on the org, click the first entry in the results, scroll to the bottom, shift-click on the last entry (to select all entries) and click the "Delete Row" button then wait while the entries are slowly deleted (takes longer for more entries).
    – Phil W
    Aug 14, 2020 at 14:14
  • Hey Phil, I tried doing the same too. But what I noticed is, even though it shows me as 2000 rows selected, when I hit the delete it deletes not more than 100 records at a time. Also it takes a lot of time to delete around 1.5 lakhs of records. So was trying to find a work around for the same. Aug 14, 2020 at 14:24
  • 1
    No argument there - it is clunky and slow. We'll see if someone responds with a better way!
    – Phil W
    Aug 14, 2020 at 14:27
  • Is csv file empty? One other thing I would do is try using the csv file using dataloader and see if it works? This most likely seems like a encoding issue on windows. I use a similar command on MacOS and it works.
    – javanoob
    Aug 14, 2020 at 15:23
  • @javanoob The csv file isn't empty. Do the dataloader supports ApexLogs object? As the windows has UTF-8 formatting, i have changed the command accordingly. But still no luck. Aug 14, 2020 at 15:39

4 Answers 4

7

The following worked for me

sfdx force:data:soql:query -q "SELECT Id FROM ApexLog" -r "csv" | out-file -encoding oem out.csv
sfdx force:data:bulk:delete -s ApexLog -f out.csv

With other encoding like utf8,utf16 etc SFDX was uploading a file with header only no -values,so it was giving error running force:data:bulk:delete: InvalidBatch : Records not found

1
  • And that worked. Thank you! @Pmanglani Aug 16, 2020 at 15:19
6

The following worked fine for me in MAC

sfdx force:data:soql:query -q "SELECT Id FROM ApexLog" --resultformat csv > out.csv

sfdx force:data:bulk:delete -s ApexLog -f out.csv

I have not tried on windows but the commands above should work fine.

1
  • Thank you for the answer Mohith, but In windows it's not working. May be because of the format issue. It's still throwing the same error. Aug 15, 2020 at 2:45
0

You can use sfdx-hardis command to delete all logs of an org

sfdx hardis:org:purge:apexlog

If you are not connected to an org, it will prompt you for one

This command is also available in VsCode SFDX Hardis menu Debugger

enter image description here

0

enter image description here

The following worked fine for me in Window VS Code. Please run these two commands:

 1. sfdx force:data:soql:query -q "SELECT Id FROM ApexLog" -r "csv" | out-file -encoding oem out.csv`

 2. sfdx force:data:bulk:delete -s ApexLog -f out.csv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.