Standard Campaign Influence only tracks last-touch attribution - custom models allow multi-touch revenue attribution
Note: This article is about Customizable Campaign Influence and not the original version of Campaign Influence.
When you create a custom model, you can use Apex triggers to add campaign influence records to the model. We recommend an approach that adds records to your custom model when Salesforce adds a record to the Primary Campaign Source model.
To implement this solution, specify an Apex trigger that defines when to create these records and what information to capture, depending on your influence tracking needs. In the example that follows, the trigger detects when a new record is added to the Primary Campaign Source model and then creates records relating the same opportunities and campaigns against your custom model.
The following example shows how to insert campaign influence records for your custom model. For other operations such as update and delete, you’ll need to create additional Apex triggers.
This example Apex trigger creates campaign influence records against the custom model you specify. By itself, this example mimics the Primary Campaign Source model, while also allowing users to add campaign influence records themselves.
You can modify the Apex trigger provided here in order to change the percentage of opportunity revenue associated with certain campaigns, or certain campaign types, such as webinars, emails, or white paper downloads. Add code to this trigger to set the Influence and RevenueShare fields on the records, based on how you would like to track campaign influence.
trigger CampaignInfluenceInsert on CampaignInfluence (after insert) {
//Create a new list of CampaignInfluence Records.
List<CampaignInfluence> campInfs = new List<CampaignInfluence>();
for(CampaignInfluence ci: Trigger.New){
//Create new CampaignInfluence records and add them to the List for
//insert since the original Salesforce Model Records are not editable
//for modelId.
if (ci.modelId == '03VR000000005qr') return;
CampaignInfluence newCI = new CampaignInfluence();
//Replace the modelId below with the ID of your custom model
newCI.modelId = '03VR000000005qr';
newCI.campaignId = ci.campaignId;
newCI.opportunityId = ci.opportunityId;
newCI.Influence = ci.Influence;
//Only insert contactId if there is one.
if(!String.isBlank(ci.contactId)){
newCI.contactId = ci.contactId;
}
//Add newly created or updated records to the new list.
campInfs.add(newCI);
}
if(!campInfs.isEmpty()){
upsert campInfs;//Insert or Update the records if the list if not empty.
}
}
Note: You can find the ID of your custom influence model by querying the Id field of the campaignInfluenceModel.
The standard campaign reports that come with Salesforce don’t include any custom model data. To see the records your custom model generates, you can
Special Notes: The code provided in this article is just an example. Salesforce Support cannot assist with issues related to this sample code or implementation, as this is outside the scope of developer support.
000381978

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.