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
Anu_gAnu_g 

Associating Campaign to a Lead

Hi,
              I have been trying to create a Lead which includes the Campaign Name.But getting the error
INVALID_FIELD: No such column 'Campaign' on entity 'lead'.
How can i take the campaign name to get it inserted into the Lead Table using the API
Any sample code is appreciated
Park Walker (TAGL)Park Walker (TAGL)
There is no direct relationship between leads and campaigns. The way you associate a lead with a campaign is to create a campaign member which references both the campaign and the lead by their respective Id values. Create the lead first and then create the campaign member using the campaign Id and the lead Id that is returned from the create call.

Park
BDSjimBDSjim
Here's an example of that...


$campaign_id = '2r2323r23'
$lead_id = 'asdf123123';

$sObject = new SObject();
$sObject->type = 'CampaignMember';
$fieldsToUpdate=array(
        'CampaignId'=>$campaign_id,
        'Status'=>'Responded',
       'LeadId'=>$lead_id,
);
$sObject->fields = $fieldsToUpdate;
$newrec=0;
$newrec = $sfcon->create(array($sObject));