I'm using node-salesforce to create leads when they submit a form. I need that lead to also be part of a campaign, here is my code:

   email : req.body.signUpEmail,
   firstname : req.body.first_name,
   lastname : req.body.last_name,
   title : req.body.job_title,
   company : req.body.company,
   leadsource: 'Clearing Microsite'
}, function(err, ret) {
   if (err || !ret.success) { 
       return console.error(err, ret); 

I've tried just putting campaign_id in the json object but no luck, any ideas? I have the campaign_id.


You need to create a campaignMember record to link the Lead and the Campaign together after creating the Lead. That record is auto-created when creating a Lead (and filling the Campaign field) via the GUI but it's not available via the API.

There's a SFDC help article on this as well: https://help.salesforce.com/apex/HTViewSolution?id=000004171&language=en_US

  • so after I create the lead i'll have to create another sobject using the newly created lead's id like so: conn.sobject("campaignMember").create({lead_id: *leadsID*, campaign_id: campaign_id})
    – benharris
    Nov 6 '14 at 15:19
  • that is correct. Nov 6 '14 at 15:21
  • If this works I am going to be so happy man! Thank you for your help, never would have guessed that, will reply if it works.
    – benharris
    Nov 6 '14 at 15:24
  • You legend, worked like a charm! Thank you man, would upvote so hard if i had the reputation.
    – benharris
    Nov 6 '14 at 15:29
  • @guy I came across the same situation for SalesForce SOAP API in C# application. But I could not find any good example to start with. Do you have any code snippet to illustrate this?
    – YuDroid
    Dec 30 '14 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.