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
gringoesegringoese 

Assign Leads to Campaigns direct from .NET instead of Web-to-Lead

Can anyone recommend the best approach for assigning Leads to Campaigns without using a Web-to-Lead form? I have a .NET/C# website with multiple campaigns on it and I don't want  the visitors to have to fill out a form every single time.  
Best Answer chosen by Admin (Salesforce Developers) 
Mike LeachMike Leach

Try something like the following:


CampaignMember campMember = new CampaignMember();

campMember.LeadId = [leadID];

campMember.CampaignId = [CampaignId];

campMember.Status = "Responded";

 

 

All Answers

werewolfwerewolf
If you know the campaign ID that you want to add the lead to, then make your .NET create a CampaignMember for that lead and that campaign ID just after it creates the lead itself.
Mike LeachMike Leach

The dialogue script Campaign Responder control does precisely this. Provide a campaignID and lead/contact ID, and it will auto-create a CampaignMember response record.

 

 

SudarshSudarsh

I'm facing the same problem. I'm creating a Lead. I want to link it to an existing Campaign. The ID of the Campaign is available. I do not know how to link it to the Lead. Could someone help with some C# code sample?

(I'm using the Enterprise API)

Here is what I have done right now...

 

Lead SFLead = new Lead();SFLead.Title = "Title";

SFLead.FirstName = "First Name";

SFLead.LastName = "Last Name";

SFLead.Email = "myemail";

SFLead.Phone = "123456789";SFLead.MobilePhone =

"987654321";SFLead.Company = "My Company";

SFLead.Description = "Description";

SFLead.Campaign= ???;

 

SuperfellSuperfell
You would insert a campaignMember object, with references to the lead & the campaign.
Mike LeachMike Leach

Try something like the following:


CampaignMember campMember = new CampaignMember();

campMember.LeadId = [leadID];

campMember.CampaignId = [CampaignId];

campMember.Status = "Responded";

 

 

This was selected as the best answer
SudarshSudarsh
Thank you Cubic, But what if I update a Lead so that the Campaign also change. Create another CampaignMember or should I have to track the CampaignMember ID and update it?
Mike LeachMike Leach

Hi Sudarsh,

 

Create a new CampaignMember object for each Campaign response. Salesforce will auto update the status for repeated responses to the same campaign. Notify your Marketing users to use the campaign influence reports to view this activity.

 

-Mike