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
SantoSanto 

getServerTimeStamp - How to pass value to query function

I am trying to create a program that read data from salesforce based on the last time the data was

modified. I want to use the local time at the remote server, and save it locally. Why do I need to add 7 hours in order to get the correct results. I should be able to get the remote time, save it, and pass it to the query. Then repeat this several time.

This is the code in question:

     TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));

     String last_run_date = query_sybase("select last_run from my_time");

      //last_run_date format is   "yyyy-MM-dd'T'HH:mm:ss" + "Z"

     Calendar mycal = sforce.getServerCal();
     mycal.add(Calendar.HOUR, 7);
     sforce_time = new Timestamp(mycal.getTime().getTime());

     fields = "ActualStartofCare__c , AmbulatoryStatus__c"
         + ",Branch__c,CloseDate,CreatedById, CreatedDate"
         + ",SocialSecurity__c,StageName,SystemModstamp,TypeofCare__c";

     sql_where = "where  stagename != 'Cancelled' )"
         + " and SystemModstamp > " + last_run_date
         + " and lastmodifiedbyid != '00530000000c0nlAAA'";

     QueryResult qr;
     query = "Select " + fields + " from opportunity " + sql_where;

     qr = sforce.query(query);

      //save last_run_date to database

adamgadamg
I'm not sure I'm reading your code correctly, but if you need add 7 hours there is something wrong with your time zone math, or how you are communicating time zone to sforce. I'd try testing the query in the .net tool at sforce.sf.net, get the right target query for sforce, and then work backwards to build it.. (time zone date formatting can be a bit of an art..)
SantoSanto

In very few words, I want to do the following:

          1. Get Server Time (sforce) - new time

          2. Save Server Time to dabase for future use - new time

          3. Query sforce using Server Time using old time

          4. Wait for 5 to 10 minutes. 

          5. Get Server Time from database - old time

          6. Repeat Step (1 to 5)

When program run for first time, old time could have any value. After, that old time will be 5 to 10 minutes less than the Server Current Time.