There is a report on Leads in my Salesforce instance which has a few filter criteria. The report is giving me 1716 lead records.
Now I want to replicate the same logic in an SOQL and then fetch the same records using SOQL. But the SOQL I've written is excluding some of the records and it's returning fewer records. I'm not able to understand why it's happening.
Here are the criteria on Lead Report:
And following is the SOQL
SELECT
Id, Email, LeadSource, Area__c, CreatedDate
FROM
LEAD
WHERE
LeadSource NOT IN ('Outbound','Phone','in-product-referral','Referral - Customer','DiscoverOrg','Zoom Info','ZoomInfo','sellhack')
AND
Email != ''
AND
(NOT LeadSource LIKE '%referral%')
AND
(NOT LeadSource LIKE '%Referral%')
AND
(
(
(NOT Email LIKE '%gmail%') AND
(NOT Email LIKE '%yahoo%') AND
(NOT Email LIKE '%hotmail%') AND
(NOT Email LIKE '%tenfold%')
)
OR
(
(
LeadSource LIKE '%LiveChat%' OR
LeadSource = 'Web - Live Chat'
) AND
(
(Email LIKE '%gmail%') OR
(Email LIKE '%yahoo%') OR
(Email LIKE '%hotmail%')
)
)
)
AND
Duplicate_Lead_Flag_new__c = False
AND
LeadSource != ''
AND
CreatedDate >= 2017-06-01T00:00:00Z
AND
CreatedDate <= 2017-06-30T23:59:59Z
Can someone help here?