Skip to main content


Showing posts from April, 2018

Using the CLI and Powershell

Deleting: First, write the list of records to a file (you could just save to a variable but it can come in handy to keep a list of IDs when modifying records).  Make sure to encode the file as ASCII and remove all the quotes or Salesforce will refuse to cooperate after the next step.

force query --format csv "SELECT Id FROM Object__c WHERE Field__c = 'Whatever'" | % {$_ -replace '"', ''} | Out-File .\ids_to_delete.csv -Encoding ASCII

(Big thanks to Ed over at the excellent Hey, Scripting Guy! blog for demonstrating this elegant way to remove the quotes)

Next, pass the CSV over to the bulk API:

force bulk delete Object__c .\ids_to_delete.csv

Or, if you just have a medium-sized list of IDs to delete and they're not in a CSV or coming from a query (e.g. copypasta from elsewhere), just paste them right into the command line as one big string and .Split() them, like this:

"axxx000000xxxxxAAA axxx000000xxxxxAAA etc".Split(" ") | %…