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
Alok_NagarroAlok_Nagarro 

Adding person account as campaign member

Hi,

 

I want to add person account to campaign as campaign member using apex, but was not able to find out  the way to pass account id in campaign member object.

 

Since i read  through some blogs that person account is treated as contact in SF so i passed accountid to contactId field of CampaignMember object. But got the "FIELD_INTEGRITY_EXCEPTION, Contact ID: id value of incorrect type: 001P000000XhJYkIAN: [ContactId]" error

 

My code is as below -

 

CampaignMember cm=new CampaignMember(CampaignId='701P00000001sWP',contactId='001P000000XhJYk',Status='Sent');
insert cm;

So hw i would pass person account id to CampaignMember object..?

 

VladMoushkovVladMoushkov

Hi , know its a late reply, but just in case someone else needs this solution:

 

PersonAccount entity has 2 Ids : Id and PersonContactId.  It is the value of PersonContactId you need to pass to the ContactId property in CampaignMember .

 

Code:

 

var qr=sforceService.query("SELECT Id, PersonContactId FROM Account where Id = '001f00000076hzq'");

var personContactId = qr.records[0].Any[1].InnerText;

 

CampaignMember cm=new CampaignMember(CampaignId='701P00000001sWP',contactId='personContactId',Status='Sent');
insert cm;