3

I am trying to a REST call from java and trying to query LEAD entity to get all Leads that were created on a particular date/date range. I am unable to get working query for the same.

I am doing something like this:

HttpGet get = new HttpGet(loginInstanceUrl+ "/services/data/v33.0/query?q=Select+Id+,+FirstName+,+LastName+,+Company+From+Le‌​‌​ad");

This gives me list of all Leads. I tried adding a where clause here something like Where CreateDate=3/25/2015 but then query fails with CreateDate is not a column on Lead Entity.

4
  • 1
    Could you share your code? Mar 25, 2015 at 11:11
  • you can use the date literals in SOQL as explained with examples in this article salesforce.com/us/developer/docs/officetoolkit/Content/… Mar 25, 2015 at 11:21
  • @sfdc_ninja,@VamsiKrishna I am doing something like this HttpGet get = new HttpGet(loginInstanceUrl+ "/services/data/v33.0/query?q=Select+Id+,+FirstName+,+LastName+,+Company+From+Lead"); This gives me list of all Leads. I tried adding a where clause here something like "Where CreateDate=3/25/2015" but then query fails as CreateDate is not a column on Lead Entity. Should I use multiple query to achieve it? Thanks Mar 25, 2015 at 13:54
  • @sfdc_ninja I am doing something like this HttpGet get = new HttpGet(loginInstanceUrl+ "/services/data/v33.0/query?q=Select+Id+,+FirstName+,+LastName+,+Company+From+Le‌​ad"); This gives me list of all Leads. I tried adding a where clause here something like "Where CreateDate=3/25/2015" but then query fails as CreateDate is not a column on Lead Entity. Should I use multiple query to achieve it? Thanks Mar 25, 2015 at 14:00

3 Answers 3

2

The name of the field isn't CreateDate but CreatedDate.

The following query will, in example query all leads which were created in the current year:

SELECT id, firstname, lastname, company, CreatedDate 
FROM Lead 
WHERE CreatedDate = THIS_YEAR


/services/data/v29.0/query?q=SELECT+id,+firstname,+lastname,+company,+CreatedDate+FROM+Lead+WHERE+CreatedDate+=+THIS_YEAR
3
  • Nice catch. Her query wouldn't have worked if she had spelled it correctly, though.
    – Adrian Larson
    Mar 25, 2015 at 14:31
  • I was considering that a different question :p. nothing is going to work if you're not using the correct fields. Mar 25, 2015 at 14:33
  • Thank you @Adrian,@Samuel for quick help I got the API working :) Mar 25, 2015 at 16:58
1

Your date format is incorrect. For Date fields, you want to use the format yyyy-MM-dd. For Datetime fields, you want to use the format yyyy-MM-dd'T'hh:mm:ss'Z', of course escaping your quotes as needed. Because CreatedDate is a Datetime field, you're pretty much stuck with ranges.

'WHERE CreatedDate >= '2015-03-24\'T\'00:00:00\'Z\'
AND CreatedDate <= 2015-03-24\'T\'23:59:59\'Z\''
0

Also, I found out that if you want to retrieve all dataset you should not specify WHERE clause, like in usual SQL query.

/services/data/v29.0/query?q=SELECT+id,+firstname,+lastname,+company,+CreatedDate+FROM+Lead

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .