Query Salesforce Data in Python

Using simple_salesforce Python API

Sophia Yang, Ph.D.
The Startup

--

Source

Salesforce is probably the most annoying database I have worked with. This web page illustrates the relationships among the objects (i.e., data tables) stored in Salesforce. You might think it doesn’t look that bad. Well, in reality, the relationship of your tables can be a lot messier than this illustration. Let’s work through this and see how we can query salesforce data while remaining sane.

Objects

Where can we find what tables and variables are available in Salesforce? To get an overview of all the tables (objects) and variables (entities). We can go to Salesforce `Developer Console — File — Open — Objects` to get a list of tables in Salesforce. And if we double click on one Object, we can see all the variable names. We can also query data directly in the Developer Console. But I prefer to use Python to do all the queries.

Naming conventions

Two things to keep in mind before we start querying:

Custom object

We can create various custom objects in Salesforce. They all end with __c. The variables will be named like objectname__c in the table.

Parent-child relationship

--

--