In Pandas, I want to pull Opportunity data with CreatedDate >= 1/1/2015.
Currently, I am extracting all Opportunity data before filtering for CreatedDate. Is it possible to optimize this process by adding the CreatedDate condition to the query?
Current State:
query_result = service.query("SELECT ID, CreatedDate FROM Opportunity")
records = query_result['records']
oppty = pd.DataFrame(records)
oppty = oppty[(oppty['CreatedDate'] >= '2015-01-01')]
Yes, you can add the condition to the salesforce query, e.g.
SELECT ID, CreatedDate from Opportunity WHERE CreatedDate > 2015-01-01T00:00:00Z
As CreatedDate is a Date/Time field, you need to provide a full dateTime for the comparison value.
the SOQL docs cover all these. There are also tools like SoqlX, Workbench etc that let you run add-hoc queries, these are useful for trying things out without having to run your full integration.