[SalesForce] Confusion with CampaignMember Object

I'm confused with LeadId and ContactId fields, these are contacts or leads associated with a campaign, to my understanding, it's who was a prospect (lead or contact) at the moment of associating with campaign. When I run a query:

select count(id) from CampaignMember where LeadId != null and ContactId != null

And… I get a list of CampaignMembers with both lead and contact id fields! How?

In addition, when I join converted leads on CampaignMembers (contactId and convertedContactId) I see that some of the associated contacts were leads before, while leadId is empty. Doesn't make sense. Thanks!

Best Answer

From my experience working with the CampaignMember object, I see the following scenarios:

1. CampaignMember with Lead
CampaignMember.LeadId is populated
CampaignMember.ContactId is null

2. CampaignMember with Contact
CampaignMember.LeadId is null
CampaignMember.ContactId is populated

3. CampaignMember with Contact who is already a converted Lead
CampaignMember.LeadId is null
CampaignMember.ContactId is populated

4. CampaignMember with Lead, then Lead is converted to Contact
CampaignMember.LeadId is populated
CampaignMember.ContactId is also populated

In writing custom logic to determine if I should be using the Contact or Lead lookup on CampaignMember, I first check if ContactId is populated. If it's not, then I fallback to the Lead.

Related Topic