Skip to main content

Posts

Showing posts from April, 2018

Using the Force.com 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)

Or perhaps a syntactically simpler way using JSON that avoids the need for quote replacing:

force query --format json "SELECT Id FROM Object__c WHERE Field__c = 'Whatever'" | ConvertFrom-Json | Export-Csv .\ids_to_delete.csv -Encoding ascii -NoTypeInformation

Either way, next pass that CSV to the Salesforce bulk API:

force bulk delete Object__c .\ids_to_delete.csv

Or, if you just h…