0

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!

4
  • So you are trying to reconcile what you observe - a CampaignMember with both a ContactId and LeadId against the documentation: Each record has a unique ID, and must contain either a ContactId or a LeadId, but can't contain both ?
    – cropredy
    Commented Dec 3, 2015 at 18:39
  • @crop1645 exactly, though I couldn't find any such statement in documentation (either LeadId or ContactId but never both together).
    – NGix
    Commented Dec 3, 2015 at 21:53
  • The doc is here: developer.salesforce.com/docs/atlas.en-us.object_reference.meta/…. I just did a query in my PROD org and saw I had 29 with both contactId and leadId for the current MONTH
    – cropredy
    Commented Dec 3, 2015 at 22:36
  • If a contact has been converted from a lead it may still have its old leadId. Commented Mar 5, 2021 at 18:03

2 Answers 2

1

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.

1
  • excellent - I'd suggest you provide feedback to the SFDC doc as said doc is at best misleading or worse, in error
    – cropredy
    Commented Dec 4, 2015 at 15:42
1

The API doc on CampaignMember states:

Each record has a unique ID, and must contain either a ContactId or a LeadId, but can't contain both.

I observed the following in my PROD org using this query:

select campaign.name, name, leadId, lead.firstname, lead.lastname, lead.isConverted, 
      contactId, contact.firstname, contact.lastname 
  from CampaignMember 
  where LeadId != null and ContactId != null and createdDate = THIS_MONTH

I had 29 hits. Everyone of them had Lead.isConverted = true

The doc gets even weirder:

Supported Calls For API version 15.0 and earlier:create(), delete(), describeLayout(), describeSObjects(), getDeleted(), getUpdated(), query(), retrieve(), update(), upsert()

For API version 16.0 and later: upsert()

but this can't be right - I just did the query above in V35.0

There is also this statement under Usage

Standard fields from a Contact or Lead are associated with the CampaignMember object but you can’t query them directly. To include a lead’s Phone in your query, for example, query the field from the Lead object.

SELECT Id, (SELECT Phone FROM Lead) FROM CampaignMember

This syntax doesn't work at all. Standard dot notation syntax worked just fine.

I'm not a regular user of these objects so someone else may have a better answer but I can see why you are confused.

2
  • 1
    The doc you linked in the comment on the question states this: Only use a ContactId or LeadId, but not both, *unless* you want to track lead-based campaign members you convert to contacts. so according to it you can have both (except when inserting - Any attempt to *create* a single record with both results in a successful insert but only the ContactId will be inserted the campaign member) kind vague and requires a lot of reading between the lines
    – Eric
    Commented Dec 4, 2015 at 4:16
  • yeah, I saw that too and decided that I couldn't trust anything written in the doc, @Ualj has a good experiential evidence answer below
    – cropredy
    Commented Dec 4, 2015 at 15:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .