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
Mike @ PartnersMike @ Partners 

Adding Campaign to a contact with the php5 toolkit

I am trying to add a Campaign to a contact using the API. im a little lost on where to begin. Do i need to run a query to update the Campaign with the contact ID number i would like add to it, or do i update the contact with the Campaign id. Any ideas would be very helpful.

Thank you,

mike

Mike @ PartnersMike @ Partners
I figuerd it out. You need to create a new CampaignMember and when you creat that you put in the ID of the campaign and the Id of the contact/lead.
Tran ManTran Man
You actually want to add contacts/leads to a campaign.  Contacts and leads are added as "CampaignMember" objects.  The object has references to LeadId, ContactId, and CampaignId.

You may find it helpful to use the AppExchange Eclipse Plugin or AppExchange explorer to browse the schema.
webjoneswebjones
Mike - I'm trying to do the same thing, but am a bit confused. Can you share a bit of code to demonstrate how you acheived this?

thanks much,
michael
Mike @ PartnersMike @ Partners
  $Idc = '1246598sd13'; //your contact Id number goes here
 $CampId ='70130000000Bx1V'; //your campgin number goes here
     $fieldsToupdate
       = array('CampaignId'=>$CampId, 'ContactId' =>$Idc);
     $sObject = new SObject();
     $sObject->fields = $fieldsToupdate;
     $sObject->type = 'CampaignMember';
     $updateRespons = $mySforceConnection->create(array($sObject));
    }

You can also add Leads this same way, but instead of using 'ContactId =>' you would use 'LeadId =>' and then the lead ID number.

Hope this helps.
thanks,
mike