Monday, November 14, 2016

How to use Datetime in Dynamic SOQL Query in Salesforce ?


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 ?
1//format the datetime to make it Dynamic Soql ready
2String formatedDt = cutOffDateTime.format('yyyy-MM-dd'T'HH:mm:ss'Z'');
3String 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.

No comments:

Post a Comment