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
support@sinequa.comsupport@sinequa.com 

SOQL Join between Campaign and Lead provides null result for a specific campaign

Hello,

We have a lead associated with a campaign and we can check it is ok via the user interface.

But when trying to programmatically retrieve this relationship via SOQL e.g.

SELECT Campaign__c, Campaign__r.Name, Campaign__r.Id, Owner.Name, Name FROM Lead where name ='TheUserName' 

Campaign__r.Name is null

However, the following SOQL

SELECT Campaign__c,Campaign__r.Name, Campaign__r.Id, Owner.Name, Name, SystemModstamp FROM Lead where Campaign__r.Name <> ''

returns results and shows it works fine for the other campaigns.

Do you have any idea why it doesn't work for this specific campaign?

Thanks in advance
Kamran HanifKamran Hanif
I hope this solves your problem:

List<CampaignMember> campaignMembers=[SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE CampaignID =: CampaignID__c];

Set<ID> LeadIDs= new Set<ID>();
For (CampaignMember CM: campaignMembers )
{
if(LeadIDs.contains(CM.LeadID)==FALSE)
{
LeadIDs.add(CM.LeadID);
}
}