Activity Forums Salesforce® Discussions How to use Datetime in Dynamic SOQL Query in Salesforce?

  • shariq

    Member
    September 22, 2018 at 6:19 pm

    This error is because of wrong construction of Dynamic Query with Datetime. following code snippet will give idea on how to construct dynamic query for Datetime ?

    //format the datetime to make it Dynamic Soql ready
    String formatedDt = cutOffDateTime.format('yyyy-MM-dd'T'HH:mm:ss'Z'');
    String sql = 'SELECT  a.Id  FROM  Agents_Answer__c a    WHERE  a.Agents_Test_Result__r.Agent_Name__r.IsActive__c = false AND  LastModifiedDate < '+ formatedDt ;
    Where, “cutOffDateTime” is variable of datetime type.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos