3

I have a connected app that will pull data from a salesforce Object. In order to do so, am executing the following query (and sending it through the REST API as form-url-encoded):

SELECT Name,Id,Type FROM Account WHERE Type='Customer'

When executed, it gives me the count of the objects that the query returned, as well as such objects. Since I am doing some synchronization amongst systems, I wanted to know if it was possible to put a constraint in the query such as this:

SELECT Name,Id,Type FROM Account WHERE Type='Customer' AND Update_At=CURDATE()

CURDATE() does not necessarily have to be a function native to SOQL (I can just pass a date/timestamp/etc) and the operand = can be <= and >= as well so I can get the SObjects that match that timeframe.

I am merely interested in getting just the Accounts who have been updated since x date to be concise. I know about the If-Modified-Since header, which will return (or not) the object provided the ID if the SObject has been modified since the provided date. This is not a solution for me, since I would have to do n requests + 1 just to check if all the accounts have been updated (or is this the actual way of doing it?)

0

2 Answers 2

4

TL;DR

Some example formats for an exact date would be

LastModifiedDate >= 2016-10-01
LastModifiedDate = YESTERDAY
SystemModStamp = TODAY

Or you can use Date Literals, for example:

SystemModStamp = LAST_N_DAYS:25
LastModifiedDate < LAST_30_DAYS
SystemModStamp = LAST_MONTH

Field

In terms of which field to look at, both SystemModStamp and LastModifiedDate give you info about when the record was last modified. See: When is SystemModStamp different from LastModifiedDate?

LastModifiedDate is the date and time when a record was last modified by a user, and SystemModstamp is the date and time when a record was last modified by a user or by an automated process (such as a trigger). In this context, "trigger" refers to Salesforce code that runs to implement standard functionality, rather than an "Apex trigger".

Value

In terms of the filter value itself, have a read of Date Formats and Date Literals, which has plenty of useful info on this subject.

Format
Date only

Format Syntax
YYYY-MM-DD

Example
1999-01-01


Format
Date, time, and time zone offset

Format Syntax
YYYY-MM-DDThh:mm:ss+hh:mm
YYYY-MM-DDThh:mm:ss-hh:mm
YYYY-MM-DDThh:mm:ssZ

Example
1999-01-01T23:01:01+01:00
1999-01-01T23:01:01-08:00
1999-01-01T23:01:01Z

6
  • Is DateField__c the "last updated" date? As in, if I update an Accounts Object, this field will be updated?
    – idelara
    Commented Nov 1, 2016 at 22:55
  • That field would be LastModifiedDate, or you may be interested in SystemModStamp.
    – Adrian Larson
    Commented Nov 1, 2016 at 22:56
  • Do you happen to know 1. The date format? 2. A link where can I look further into this? Many thanks!
    – idelara
    Commented Nov 1, 2016 at 22:59
  • Also, will my final query be the following then? SELECT Name,Id,Type FROM Account WHERE Type='Customer' AND LastModifiedDate < 2016-11-01 or can LAST_N_DAYS:25 work for LastModifiedDate as well?
    – idelara
    Commented Nov 1, 2016 at 23:01
  • 1
    Thank you for your help. Will check it out ASAP. Many thanks!
    – idelara
    Commented Nov 1, 2016 at 23:09
2

getUpdated() is the preferred way to do mirroring, if you're calling the SOAP API, or SObject Get Updated if you're using the REST API. This API gives you records updated since X time, and even tells you records that are "in-flight" but haven't been committed yet. This allows you to make sure that you don't miss records that were in-flight since the last check. You can also use date literals, such as "today", but getUpdated allows much more granular replication. There's also a similar function to find records that have been deleted (hard or soft) since the last replication.

When using the REST API, your request will look like this:

/services/data/v29.0/sobjects/Account/updated/​​​?start=2013-05-06T00%3A00%3A00%2B00%3A00&end=2013-05-10T00%3A00%3A00%2B00%3A00

Where start and end are the date ranges you want to cover. You'll get back a result that looks like this:

{ 
    "ids" : 
    [ 
        "001D0000008pQR5IAM", 
        "001D0000008pQRGIA2", 
        "001D0000008pQRFIA2"
    ],
    "latestDateCovered" : "2013-05-08T21:20:00.000+0000" 
}
2
  • Is there such functionality for REST? I would use SOAP but my hands are tied to REST as of now... many thanks for your response
    – idelara
    Commented Nov 1, 2016 at 23:02
  • @JackGal Yes, sorry, I forgot about the REST version. I've added a link for you.
    – sfdcfox
    Commented Nov 1, 2016 at 23:04

You must log in to answer this question.

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