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
tssupporttssupport 

Using a DateTime in filter query

I'm trying to use a DateTime in a filter query. When I try to execute the query I get the following exception:

The server returned the following fault information:
Fault Code: 1003
Fault string: null parameter

What am I doing wrong? Using filters with other fields is no problem, just datetime fields.
The code I'm using follows below (C#, SOAP API).

public bool testDateTime(){  
   Logon();
   object[] ret;
   DateTime lastTime = DateTime.Now.AddDays(-2);

   object[] filter = new object[] {
      MakeSimpleFilter(
         "lastModifiedDate",
         lastTime,
         "greater than"
      )
   };

   string[] selectList = new string[]{
      "id",
      "name",
      "lastModifiedDate"
   };   

   try{
      ret = (object[]) sForce.query("opportunity", 20, true, selectList, filter);
   }catch (SoapHeaderException ex) {
      //This is typical error handling for fault detection and reporting, the .Net Proxy client actually throws an
      //error rather than return the fault SOAP Message.
      Trace.WriteLine("The server returned the following fault information:");
      Trace.WriteLine("Fault Code: " + ((XmlQualifiedName)  ((SoapException)ex).Code).Name);
      Trace.WriteLine("Fault string: " + ex.Message);
      return false;
   }
   //Parsing of reply
   return true;
}

regards

Daniel
Ki Consulting