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

SOQL Date Comparison Error (MALFORMED_QUERY) Through API



I am trying to execute, what I believe is a very simple SOQL query with a Date comparison through the API "Binding.Query" method, but I continue to get the following error message. Any help is very much appreciated!


The Query:


SELECT Id, Company_ID__c, Last_Modified_Date__c, Last_Sync__c

FROM Account__c WHERE ((Company_Id__c = null) OR (Last_Sync__c = null) OR (Last_Sync__c < Last_Modified_Date__c)) 


The Error Message:

System.Web.Services.Protocols.SoapException: MALFORMED_QUERY: 
(Last_Sync__c &lt; Last_Modified_Date__c))
ERROR at Row:7:Column:79
unexpected token: 'Last_Modified_Date__c'
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Syncer.sforce.SforceService.query(String queryString) in ...\SalesforceWebService\Syncer\Web References\sforce\Reference.cs:line 1077
at Syncer.SforceAPI.Query(String objectType, Int32 objectId) in ...\SalesforceWebService\Syncer\SforceAPI.cs:line 226
at Syncer.Customer_Salesforce.GetUnsyncedCustomers(Int32 companyId) in ...\SalesforceWebService\Syncer\Customer.cs:line 617
at SalesforceWebService.Service1.GetUnsyncedCustomersFromSalesforce(Int32 companyId) in ...\SalesforceWebService\SalesforceWebService\Service1.asmx.cs:line 94







the right hand side of a filter clause needs to be a literal value, not another column.
It's for your helpful : 
[SELECT Id, Company_ID__c, Last_Modified_Date__c, Last_Sync__c FROM Account__c WHERE ((Company_Id__c =: null) OR (Last_Sync__c =: null) OR (Last_Sync__c < :Last_Modified_Date__c)) ];

if help then Please mark it.