Clemson
Clemson

Reputation: 506

How do I make an SOQL Query with Spaces in Column Names?

I'm trying to make an SOQL query using the simple_salesforce python package. I'm having a bit of trouble querying columns which have spaces in the column names:

sf.query_all("SELECT Id, Name, Email FROM Lead WHERE `Lead Source`=Calculator (Website)")

I'm trying to use the conventional SQL syntax of dealing with pesky column names (I have also tried [] brackets) but I keep getting a SalesforceMalformedRequest.

I want to get a python dict which contains the IDs, Names and Emails of any leads that have a lead source of 'Calculator (Website)'.

I don't have privileges to change the column names, so any help on how to query, or how to access the column names in some other way, would be a lot of help!

Upvotes: 1

Views: 3612

Answers (1)

martin
martin

Reputation: 1182

As @user2864740 mentioned in the comments above, Salesforce doesn't allow spaces in field api names. In this situation, assuming you are trying to query the standard field with the English label of "Lead Source", the api name is LeadSource

enter image description here

You would want your query to be:

sf.query_all("SELECT Id, Name, Email FROM Lead WHERE LeadSource = 'Calculator (Website)'")

Upvotes: 2

Related Questions