function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
spandyaspandya 

getUpdated time range with python suds

I'm trying to use the Salesforce SOAP API in python to poll for updated items in a Salesforce account. I'm stuck on code that looks like this:

 

pollingInterval = 5 * 60 # 5 minutes

now = s.getServerDatetime()

updatedContacts = s.getUpdated('Contact', now - datetime.timedelta(seconds=pollingInterval), now)

 

where s.getUpdated(...) just calls the SOAP function "getUpdated." I've set the time  range to be starting from 5 minutes in the past and ending at the current moment. This doesn't return any data. The "latestDateCovered" is always several hours in the past. If I set the end date to be some point in the future (such as 100 days), it returns some data, but it returns the same data every 5 minutes. In that case, the "latestDateCovered" is the same as the server time. I tried adjusting for my time zone, as well as daylight savings, but to no avail. Does anyone have any idea what the proper way to do this is?

ShakilShakil

for same requirement, you can write code in different way. With refering to LastModifiedDate , which you can use key to get recently updated accounts. I am sure it will resolved.

XXXXXX

I am approaching this problem from the opposite side -- I have a working application that looks for records with a LastModifiedDate after a certain point in time. This works fine until I run it against a table with > 1 million records in it, and then I get a query timeout error (after two minutes).

 

Someone pointed me to the API getUpdated() function.

 

Does anyone have an answer to the original question? I am hoping that getUpdated() will return an answer more quickly than SELECT * FROM Table WHERE LastModifiedDate >= DATE

 

TIA,

 

John

spandyaspandya
i actually sorted out this problem myself recently. the problem was with time conversions. since i don't know much about python datetime, i had to fudge it a bit, but my solution works.

        now = client.service.getServerTimestamp().timestamp
        offset = now.utcoffset().seconds
        now = now.replace(tzinfo=None) + datetime.timedelta(seconds=offset)

this will convert the server's time to local time. there's probably a more elegant solution, but this works. i suspect your code would look something like:

        # 'now' is described above
        # 'DATE' is a datetime object representing the desired date, eg:
        DATE = datetime.datetime(2009, 5, 1, 17, 0, 0) # 5/01/2009 at 5:00pm
        client.service.getUpdated('Contact', DATE, now)

this returns a bunch of Ids over which you have to iterate and retrieve. i hope this helps.

--sagar
Message Edited by spandya on 05-22-2009 01:30 PM