Export your Salesforce Objects to SQLite

Sometimes it can be quite useful to export data you have in Salesforce Org (transferring your data over to a new system is probably the biggest use case).

Saleforce's suggestion is to use the dataloader but that has a lot of drawbacks:

  • Flat File Format only
  • Not (sufficiently) scriptable
  • Manual process to select the fields you want (instead of just everything)
  • Only one object at a time

As most of the information you need for a proper export a available via Salesforce's field description, it was pretty simple to come up with a solution that would let me export a range of objects to a database format (SQLite currently but very easy to extend for other RDBMS).

And here it is: salesforce_exporter. With a simple export command you are now able to export as many objects as the org holds:

client = SalesforceExporter.new
db = client.export(objects: ["Contact", "Account"], to: "sqlite://test.db")

Not only does it export all the data into an SQLite database; it also preserves the datatypes and sets the constraints accordingly:

  • Data types will be converted to the closest SQLite data type
  • Not Null and Unique constraints will be kept
  • Id field will be set as primary key of the according table