1

I am trying to figure out a way to associate a lead, upon creation, with an existing campaign.

I know this would involve an apex trigger/class, but I'm not sure of how to do it.

The way I want it to behave is for the trigger to "look" to a text field that will contain the Salesforce campaign name or campaign ID (whichever is easiest) and then add the lead to that campaign upon saving.

  • Did my answer help you or at least point you in the right direction? – Alex Tennant May 9 '14 at 10:39
1

You will need a after insert trigger on Lead that creates a CampaignMember object(s) and inserts it.

The CampaignMember object requires the ID of the Campaign (CampaignID field) and the ID of the Lead (LeadID field) to create it (you can also use Contacts with the ContactID field), you can also set the Status of your CampaignMember.

Once the CampaignMember object has been created your Leads should show up in the Campaign Members related list of the relavent Campaign.

  • I think you mean: after insert trigger - before insert won't have access to the lead.id – cropredy Apr 30 '14 at 22:22
  • @crop1645 Good catch, this is what happens when I answer things late at night on my phone. – Alex Tennant Apr 30 '14 at 22:26

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.