Skip to main content


Showing posts from January, 2020

Exporting from an SQL database (e.g. Dynamics) into Salesforce, without Excel

Whenever you paste content into it, Excel likes to be helpful and reformat it according to what it thinks you're doing (e.g. format dates, interpret formulae), but often with CSVs it gets this wrong and messes up your carefully-formatted raw data. This was getting pretty frustrating, so rather than figuring out workarounds for Excel's weirdness, here's how to go from an SQL query straight into Salesforce with zero copypasta.

# first, write your query and save in query.sql
Invoke-SqlCmd -ServerInstance serverName -Database dbName -InputFile 'query.sql' | Export-Csv -Path 'outputFile.csv' -Encoding ascii -NoTypeInformation
force login
force bulk -c insert -o objectName outputFile.csv

Invoke-SqlCmd is in the SqlServer module, so you'll need that first, and you'll also need the CLI installed. As a bonus, this method also removes the need to replace NULLs in the output, since they get rendered as an empty field in the CSV.