3

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:

enter image description here

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?

  • Is the report constrained to records created in June as well? – IllusiveBrian Aug 4 '17 at 23:16
  • Do you have any Leads where Duplicate_Lead_Flag_new__c = Null? – Jeff Bennett Aug 4 '17 at 23:17
  • Yes. The report shows the records which are created in the month of June only. – Udit Desai Aug 4 '17 at 23:28
  • I don't think any leads have Duplicate_Lead_Flag_new__c value as Null. However, I also tried the SOQL with Duplicate_Lead_Flag_new__c != True which would cover your hunch. But it did not give all the records. The records were still missing. – Udit Desai Aug 4 '17 at 23:38
0

Not sure, it seems very strange that the SOQL would return fewer records. Is this report type Lead or can you be using a custom joined report type? You might also consider comparing the results of both and see what is missing from SOQL return and that might give you a clue of what is going on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.