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
Sridhar Reddy 65Sridhar Reddy 65 

SOQL is not working as intended

Hello all,

I have below query which should only pick records which have assets created on or after 2018-01-01 and ((LastModifiedDate >= 2018-01-01T08:00:00.000+0000 and LastModifiedDate <= 2018-01-13T08:00:00.000+0000) OR (Last_Integration_Run_Date__c = null))

SELECT Id,Related_Opportunity__r.Id,Related_Opportunity__r.DRG_Order_ID__c, SBQQ__ReferenceContract__r.ERP_Order_ID__c,SBQQ__ReferenceContract__r.Quoted_Currency__c FROM Asset WHERE SBQQ__ReferenceContract__c != '' and Account.Id != '' and Related_Opportunity__r.Finance_Approved__c = true and ERP_DoNotIntegrate__c = false and CreatedDate>=2018-01-01T08:00:00.000+0000 AND ((LastModifiedDate >= 2018-01-01T08:00:00.000+0000 and LastModifiedDate <= 2018-01-13T08:00:00.000+0000) OR (Last_Integration_Run_Date__c = null))

But the above query is also picking assets created before 2018-01-01, can some please let me know if anything is missing in my query which is making it to pick assets which are created before 2018-01-01.

Any help is highly appriciated since this is urgent.

Best Regards,
Sridhar
Best Answer chosen by Sridhar Reddy 65
Scott Nelson SolutionistScott Nelson Solutionist
You probably need to adjust the time of your where clause to account for your time zone. The time displayed in the form is your profile time zone, but the time stored in Salesforce is GMT. That would explain it if the only extra records you are picking up are within a day of your query. 

All Answers

Scott Nelson SolutionistScott Nelson Solutionist
OR (Last_Integration_Run_Date__c = null)

is causing your problem. Try: 
OR (CreatedDate>=2018-01-01T08:00:00.000+0000 AND Last_Integration_Run_Date__c = null)

HTH
Scott S Nelson
Sridhar Reddy 65Sridhar Reddy 65
Hi Scott,

Thanks for help, but it did not work. Below is the image of dates on which this assett is created and modified.
Can you please help me.


User-added image

Best Regards,
Sridhar
Scott Nelson SolutionistScott Nelson Solutionist
You probably need to adjust the time of your where clause to account for your time zone. The time displayed in the form is your profile time zone, but the time stored in Salesforce is GMT. That would explain it if the only extra records you are picking up are within a day of your query. 
This was selected as the best answer
Sridhar Reddy 65Sridhar Reddy 65
Hi Scott,

Yeah thats the problem. Thanks for all your help and support.

Best Regards,
Sridhar
Scott Nelson SolutionistScott Nelson Solutionist
If that did the trick, please mark as best answer :)
Sridhar Reddy 65Sridhar Reddy 65
I did, thanks for help Scott.