Using the CLI and Powershell

Inserting or Updating:

Put all your data into a CSV file with the exact same column headings as the Salesforce fields, again making sure to save as ASCII and not UTF8 or any other encoding (in Excel, you want the option called "CSV (Comma delimited)" not "CSV UTF-8"). And then do this:

force bulk insert Object__c .\new_object_data.csv

To modify fields for updating, don't do the updates in Excel unless you have to - do it inline like this:

force query --format json "Select whatever from Object" | ConvertFrom-Json | %{$_.Some_Field__c = 'whatever'; $_} | select Id,Some_Field__c | Export-Csv .\updates.csv -NoTypeInformation -Encoding ASCII

Note the following:
The foreach (%) block at the end it returns the object being iterated over. This is really important otherwise it won't pipe anything through to the "select".
Speaking of the "select", you have to select only the fields you're working with, because "force query" returns an extra "attributes" field and Salesforce will get very confused if you include it.

Then just do the following:

force bulk update Object__c .\updates.csv


If you're deleting the result of a bulk export, download the result csv and run this:

get-content 'result' | convertfrom-csv | where Id -NE '' | select Id | export-csv 'delete.csv' -NoTypeInformation -Encoding ASCII
force bulk delete Object__c 'delete.csv'

Otherwise, 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 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(" ") | % { force record delete Object__c $_ }

Querying Metadata:

For getting a list of fields, which I need to do all the time:

(force describe -t=sobject -n=Object__c | convertfrom-json).fields | select name

Check out the output from just the part inside the parentheses to see all the other metadata you can use. It's easier to just make this a Powershell function and add it to your PS profile if you use this a lot, though.


You can query both ObjectPermissions and FieldPermissions to get the permissions of a particular profile on different things:
force query "SELECT Id, SObjectType, PermissionsRead, PermissionsCreate FROM ObjectPermissions WHERE parentid in (select id from permissionset where PermissionSet.Profile.Name = 'System Administrator')"

For FieldPermissions it's almost the same, but the fields are slightly different and you also need to add a "WHERE SobjectType = 'Custom_Object_Name__c'"

User Profiles:

Get a count of users in each profile like this:
$users = force query --format json "select, user.Email, user.FirstName, user.LastName,, user.Username, user.IsActive FROM user where user.isactive = true limit 1" | convertfrom-json
$users | select -expandproperty Profile | select -ExpandProperty Name | group

Logging into a sandbox:

Obviously replace the domain below with the domain of your sandbox:

force login -i=""