4

This is what I've tried so far.

I get the current timestamp, format it to the Date format and append it to the query.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];

NSString *lastModifiedDate = [dateFormatter stringFromDate:[NSDate date]];
NSMutableString *query = [[NSMutableString alloc ] initWithString:@"select Id, Name, LastModifiedDate FROM Contact LastModifiedDate > "];

[query appendString: lastModifiedDate];

SFRestRequest *request = [[SFRestAPI sharedInstance] requestForQuery: query];
[[SFRestAPI sharedInstance] send:request delegate:self];

This is the error I get.

2013-06-21 16:59:07.209 FMDB01[4624:c07] SFRestAPI::send: <SFRestRequest 0x9ca5380 
endpoint: /services/data 
method: GET 
path: /v23.0/query 
queryParams: {
 "q" : "select Id, Name, LastModifiedDate FROM Contact WHERE LastModifiedDate > 2013-06-21 04:59:07"
} >
2013-06-21 16:59:08.517 FMDB01[4624:c07] error: Error Domain=com.salesforce.RestAPI.ErrorDomain Code=999 "The operation couldn’t be completed. (com.salesforce.RestAPI.ErrorDomain error 999.)" UserInfo=0x9ca9a70 {message= 
LastModifiedDate > 2013-06-21 04:59:07
                                     ^
ERROR at Row:1:Column:162
line 1:162 no viable alternative at character '<EOF>', errorCode=MALFORMED_QUERY}
2013-06-21 16:59:08.517 FMDB01[4624:c07] request:didFailLoadWithError: Error Domain=com.salesforce.RestAPI.ErrorDomain Code=999 "The operation couldn’t be completed. (com.salesforce.RestAPI.ErrorDomain error 999.)" UserInfo=0x9ca9a70 {message= 
LastModifiedDate > 2013-06-21 04:59:07
                                     ^

I tried passing the DateTime field in single quotes and I get an error saying value of filter criterion for field 'LastModifiedDate' must be of type dateTime and should not be enclosed in quotes, errorCode=INVALID_FIELD.

Any help on how to proceed will help! Thanks in advance!

5

The Datetime format that Salesforce uses cannot be formatted using NSDateFormatter. MobileSDK has a util class SFDateUtil that can be used to convert NSDate into formatted string.

NSString *dateInString = [SFDateUtil toSOQLDateTimeString:[NSDate date] isDateTime:true];

This gives the datetime in yyyy-mm-ddThh:mm:ss.000Z. This String can be used in query. The same method can be used for Date too.

| improve this answer | |
4

Try to modify your LastModifiedDate to the following format:

2013-06-21T00:00:00.000Z

So add T00:00:00.000Z to the 2013-06-21 without white space (generally format it like this: yyyy-mm-ddThh:mm:ss.000Z)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.