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
Jerome MaddenJerome Madden 

Need to automatically link opportunity to a campaign

Obviously we can automatically link opportunities to campaigns out of the lead conversion process, but the majority of our opportunities from campaigns come many months later, and its not realistic or reasonable to ask our reps to remember to manually link the new opportunity to the campaign.

How do we get this to happen automatically?  If we get a contact from a campaign, is there a way to automatically link the opportunity associated with that contact to the most recent campaign that they were assocated with?
PratikPratik (Salesforce Developers) 
Hi Jerome,

Automatically through code it can be done!

Logic:

To identify the contact associate with opportunity(opportunity contact role) and then identifying it's recent campaign of which he is a campaignmember and then add the same campaign to opportunity.
This will work for a single contact common between opportunity & campaign.

The issue will be if there are multiple contacts associated wirh the campaign & opportunity then which contact you will select.

Will you please let me knwo how you will identify the contact between opportunity & campaign or is there any customization in your org for it.

Thanks,
Pratik