作者:WingKeii- | 来源:互联网 | 2023-10-13 10:29
【前言】:在19年8月份的时候,为地产行业客户实施了一套简要的CampaignInfluence模型,目的是帮助房产公司市场部同事了解什么类型的Campaign有助于产生新的商机,
【前言】:在19年8月份的时候,为地产行业客户实施了一套简要的Campaign Influence模型,目的是帮助房产公司市场部同事了解什么类型的Campaign有助于产生新的商机,及最终成单(即了解客户成功购买归因,通过哪些市场活动触点最终进入销售关键节点),并最终计算ROI (Return On Investment)。项目落地后的一段时间工作重心放在了金融行业客户上,到21年回归地产项目数月后,在调查代码覆盖问题,及影响范围和程度时,偶然看到了相关代码的变动,因此重新测试发现确实存在一些亟待解决的问题。
【模型简述】:
模型要素:这个模型涉及到4个要素
#1. Campaign Influence Model
#2. Contact
#3. Campaign
#4. Opportunity
从数据模型角度理解如下图(1)所示:
从画面角度理解如下图(2, 3)所示:
【现存问题】:在下图(4)的Campaign Detail页面上,我们发现Opportunities in Campaign数量为1而实际根据4个要素,压根没找到对应数据。
【问题归因】:
在Org迁移的时候,担当同学忘记在新Org配置自定义Campaign Influence Model,因此该业务模块中的数据是按照Salesforce初始化的标准Model处理数据的。
使用标准Model时,即便删除了图(3)中的Opportunity上的Primary Campaign Source,这时系统自动移除了图(2)中Camapign底下的Influenced Opportunities,但是图(3)中的Opportunity的Campaign Influence并未自动移除,而图(4)中的INFULENCED OPPORTUNITIES查询的是CampaignInfluence表,因此因并未移除造成rollup INFLUENCED OPPORTUNITIES值时,图(4)中的Opportunities in Campaign显示为1 -> 与事实不符。
最终,要让SF标准行为符合预期(清除primary campaign on opp -> 删除CampaignInfluence表记录),只需要创建自定义的Model即可,如下图(5)所示:
【关于使用Model的一些考虑】:Implement Custom Campaign Influence Models with Apex Triggers
Considerations for Implementing Custom Campaign Influence Models
Note that the Primary Campaign Source model’s influence records are recalculated when any of these events occur.
Changing any Customizable Campaign Influence settingUpdating an opportunity’s Close DateAdding or removing members from campaignsDeleting or undeleting accounts or opportunities
During such a recalculation, some existing campaign influence records for the Primary Campaign Source model may be deleted and re-created. Because the approach described here creates records for your custom model whenever Primary Campaign Source records are created, it’s possible that duplicate influence records can be created against your custom model.
To avoid this duplicate record creation, include validation checks in your own Apex code to make sure you're not inserting a record with the same modelId + opptyId + campaignId + contactId into the same model. If you find that a record already exists, perform an update operation on the record instead.