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

query use lastModifiedDate field


I am runing Axis demos (java). I  did update first and then did query by Filter.

My filter is lastModifiedDate is "less than" end date which is current time and "greater than" start date which is current time - 30 second.

I noticed (I tried many times)  that even the lastModifiedDate is between the current time and current time - 30 second. query will not get the updated object. but if my start date is current time - 30 second - 60 second. I can get the object if I do query by Filter within 30 second after I did update.

current time - 30 second - 60 second <lastModifiedDate < current time

So why need 60 second .

I call get_server_timestamp to get server time and it is same as my local time (GMT)

I am thinking this many days and don't know why.





I am having a similar problem with the lastModifiedDate and createdDate fields. I want poll the API every 5 or 10 minutes to get a list of IDs for opportunities which have been created since the last poll. I'm using XML-RPC under Java. Here's a code snippit. entityName has a value of "opportunity"

    public Vector constructIdQuery(String entityName, Date afterDate)
        Vector retVal = new Vector();
        Hashtable paramList = new Hashtable();
        // Construct the query header
        paramList.put("version", version);
        paramList.put("type", entityName);
        Vector selectList = new Vector();
        selectList.add("id"); // Only interested in the IDs at the moment
        paramList.put("select", selectList); 

        // Now put the query scope and filter
        paramList.put("scope", "filter");
        Hashtable filter = new Hashtable();
        filter.put("field", "createdDate");
        filter.put("operator", "greater than");
        filter.put("value", afterDate);
        Vector filterVec = new Vector();
        paramList.put("filter", filterVec);

        return retVal;
    public Vector doQuery(Vector query) throws ApiQueryException
        XmlRpcClient rpcClient=null;
        Vector retVal = null;
            rpcClient=new XmlRpcClient(serverUrl);
            retVal =  (Vector) rpcClient.execute("sfdc.query", query);
        catch(Exception e)
            throw new ApiQueryException("Failed to query SForce API\n"+e.toString());
        return retVal;

The function which calls doQuery has the following log:

Wed Aug 20 10:35:31 BST 2003 INFO: Query to the API for opportunity since Wed Aug 20 10:13:11 BST 2003 records returned 0 records

This is despite the fact that I created an opportunity at 10:26.

I noticed that if I change the time so that the "afterDate" paramater is 9:13 then the query does find the record. I changed the query to look at the "lastModifiedDate" field and found the same behaviour.

Does this mean that the temporal resolution on time fields is one hour?




I did a call to get_server_timestamp and found that the server thinks it's 10:06 BST while Java thinks it's 11:06 BST.

I have GMT set as my TimeZone in SFDC and the createdDate timestamp on the opportunity view says "10:26" which according to the API is in the future. Is there a problem with how the API handles time zones and daylight savings?





I have similar problem with the LastModifiedDate and CreatedDate fields (leads). I have a very basic knowledge in Java, and I would like your help to find out the way to specify in the code how to retrieve the rows created or modified in the last week. Here is part of the code where the is defined the query:

private void _copyData2EO(Hashtable data) {
  EOEnterpriseObject eo = _createInstance((String)mappingModel.valueForKey("entityName"));
  Enumeration e = sfkeys.objectEnumerator();
  while (e.hasMoreElements()) {
   String aKey = (String)e.nextElement();
   if (data.containsKey(aKey)) {
    if (data.get(aKey) instanceof java.util.Date) {
     eo.takeValueForKey(new NSTimestamp((java.util.Date)data.get(aKey)), (String)sfkeymap.valueForKey(aKey));    
    } else if (data.get(aKey) instanceof java.lang.String) {
     String attributeName = (String)sfkeymap.valueForKey(aKey);
     String value = (String)data.get(aKey);
     EOEntity entity = EOModelGroup.defaultGroup().entityNamed((String)mappingModel.valueForKey("entityName"));
                    EOAttribute att = entity.attributeNamed(attributeName);
     if ("YES".equalsIgnoreCase(System.getProperty("DEBUG"))) {
      System.out.println("attribute name: "+attributeName);
     if (value.length() > att.width()) {
      eo.takeValueForKey(value.substring(0, att.width()), attributeName);
     } else {
      eo.takeValueForKey(value, attributeName);
    } else if (data.get(aKey) instanceof java.lang.Boolean) {
     String attributeName = (String)sfkeymap.valueForKey(aKey);
     Boolean value = (Boolean)data.get(aKey);
     eo.takeValueForKey(value.toString(), attributeName);
    } else {
     String attributeName = (String)sfkeymap.valueForKey(aKey);
     Object value = data.get(aKey);
     eo.takeValueForKey(value, attributeName);

It will be great if you can give me some ideas about it.




Hi CarlosRey,

The code you posted seems to be processing values from a hash table and creating some object from the data.  Beyond this, I am unable to deduce exactly what you question is or what problem you are having.  Maybe you could re-phrase your question.



The question that I have is this, how can I retrieve from the sf_lead only those records created or modified during the last week. I would like from you a code example of how to retrieve the last week data created or modified from the sf_leads.

The code I sent, take as you mentioned the data from a hash table, but I do not know how to take from that hash table the data modified or created in the last week. I did not develop that code. If you have some ideas over that code, please let me know it.




Hi CarlosRey,

Is the code that you inherited using XML-RPC or SOAP?  I assume you are using Java.  Have you looked at any of the samples on the sforce website?


FWIW, here is some code I use to grab all the leads created in the past 24 hours, owned by a particular user.  (I cron this to run nightly.)

public Element queryFilterDemo()

throws DOMException, TransformerException, ServiceException, IOException




Calendar jc = Calendar.getInstance();

jc.roll(Calendar.DAY_OF_YEAR, -1);

Object filter[] = new Object[2];

Object filt[] = new Object[1];

filter[1] = MakeSimpleFilter("ownerID", "005000000050Tzs", "equals");

filter[0] = MakeSimpleFilter("createdDate", jc, "greater than");

leadList = new Vector();

SimpleDateFormat jdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");

Calendar jc1 = Calendar.getInstance();

Element value = (Element)binding.query("filter", "lead", 100, new String[] {

"id", "lastName", "firstName", "createdDate", "company","email", "cf_00N30000000bznh"

}, filter, null, jc, false);

return value;


I am having the same problem that even though I add new records they dont show up in the query I do for new records. Is there a problem with the time stamp or queries on the createdDate fields.