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
SBNSBN 

How to pass Personaccount id to campaign member

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.

 

I  got the "FIELD_INTEGRITY_EXCEPTION, Contact ID: id value of incorrect type: 001P000000XhJYkIAN: [ContactId]" error.

 

DO I need to use "Personcontactid" to pass instead of contact id from account object ?

 

 

 



Best Answer chosen by Admin (Salesforce Developers) 
ForcepowerForcepower
snune,

I suspect you may be trying to put a contact id into an account lookup field:

email2HoldingObject.get(aitem.personemail).PersonalAccount__c = aitem.PersonContactId ;

You may want to check that specific line and see if that's where the trigger is erroring out.
Ram


All Answers

ForcepowerForcepower
snune, Campaign Member does expect a Contact Id for the Contact lookup field. So I think you're on the right track. Try using the PersonContactId instead.

Ram
SBNSBN
Thanks for the reply. I tried to pass the personcontactid . Now the trigger throws the following error:
"Apex trigger top1000csv caused an unexpected exception, contact your administrator: top1000csv: data changed by trigger for field PersonalAccount: id value of incorrect type: 003Z000000KwGUMIA3". Do you have any suggestion?
ForcepowerForcepower
The id 003Z000000KwGUMIA3 seems like a contact id. I'm not sure of the context/details of the trigger. It is somehow being triggered with the contact id rather than the account id that it is expecting. Is top1000csv a custom trigger?
SBNSBN

yes. top1000csv is a custom trigger and here is my code below:

 

for ( Holdingobject_top1000__c Ho : Trigger.new )
{
email2HoldingObject.put( Ho.email__c, Ho ) ;
if ((Ho.email__c != null) && ( ! Hobj_Emails.contains(Ho.email__c) ) )
Hobj_Emails.add(Ho.email__c);

}

 

list<account> a = [SELECT id, personemail,Member_id__c,PersonContactId from account WHERE personemail in : Hobj_Emails and IsPersonAccount =true] ;
// iterate through the contacts that were found and add them to the set and map used for contacts.
for ( account aitem : a ) {/
email2HoldingObject.get(aitem.personemail).PersonalAccount__c = aitem.PersonContactId ;
}

 

// Creating the  Campaign member  for each Hodlign object results.
for ( Holdingobject_top1000__c Ho : Trigger.new )

{

 

CampaignMember newCM = new CampaignMember(
CampaignId = campid,
LeadId = Ho.lead__c ,
ContactId = Ho.personalaccount__c,
status = 'Attended' );
insert newCM ;

 

}

 

ForcepowerForcepower
snune,

I suspect you may be trying to put a contact id into an account lookup field:

email2HoldingObject.get(aitem.personemail).PersonalAccount__c = aitem.PersonContactId ;

You may want to check that specific line and see if that's where the trigger is erroring out.
Ram


This was selected as the best answer
SBNSBN

yeah.Its referring to the contact id and I created a look up for Account object in my "Holding object" custom object. I created a new look up for contact object with name "Personcontact__c" and passed the personcontactid to this field. and the trigger is now working fine 

 

email2HoldingObject.get(aitem.personemail).Personcontact__c = aitem.PersonContactId ;

 

 

 

Thank you

ForcepowerForcepower
Excellent. Glad to hear it.
Ram