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.
Attribution to: user8170
Possible Suggestion/Solution #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.
Attribution to: Alex Tennant
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34136