You need to sign in to do that
Don't have an account?
Using 'where' clause to query Salesforce Contact entity
Hi,
This may seem to be a trivial issue, but I need some help to solve this.
I am trying to query salesforce Contact entity using REST api from a RoR application.
I am able to retrieve all the Contact entities information successfully when I only use a simple select query like:
@uri.get({:q => 'select id, firstname, lastname from Contact'}, headers) do |callback|
callback.on_ok do |response|
self.replace(response.deserialise['records'].map do |contact|
Contact.new(@salesforce_session,
'FirstName' => contact["FirstName"], 'LastName' => contact["LastName"], 'Id' => contact["Id"]
)
end)
end
But, I am getting a 400 Bad Request error when using the where clause with the above statement:
@uri.get({:q => 'select id, firstname, lastname from Contact where email = "naveen@gmail.com"'}, headers) do |callback|
callback.on_ok do |response|
puts "******************* Printing Response ********************"
puts response.inspect
self.replace(response.deserialise['records'].map do |contact|
Contact.new(@salesforce_session,
'FirstName' => contact["FirstName"], 'LastName' => contact["LastName"], 'Id' => contact["Id"]
)
end)
end
LOG:
Loading details by email id........
<- (GET -3363550491 -217275911) https://ap1.salesforce.com:443/services/data/v20.0/query?q=select+id%2C+firstname%2C+lastname+from+Contact+where+email+%3D+%22naveen%40gmail.com%22
-> (GET -3363550491 -217275911) 400 Bad Request (230 bytes 2.15s)
I understand that there is something wrong in the Request used to query salesforce. How do I ensure that the request format is correct while using a 'WHERE' clause.
Thank You,
Naveen Kumar B.V
The response body with the 400 status code will have more details on what's wrong with the request. In this case, the problem is likely that you're using " to quote the email address in the where clause, it should be done with '
All Answers
The response body with the 400 status code will have more details on what's wrong with the request. In this case, the problem is likely that you're using " to quote the email address in the where clause, it should be done with '
Thanks Simon,
It was a problem with ' and ". Works fine when queried this way:
" select id, firstname, lastname from Contact where email = 'naveen@gmail.com' "