Salesforce:在导致联系人转换后将带有数据的自定义对象移动到联系人?
我有一些潜在客户有一个自定义浏览活动对象,用于存储他们浏览的链接。当我将潜在客户转换为联系人时,除自定义对象之外的所有内容都会被转移。有没有办法通过触发器或 C# 代码在转换后导入带有数据的自定义对象?
任何帮助将不胜感激。谢谢
您的回复。 这是我到目前为止所拥有的。我无法获取浏览数据;它只获取与该活动相关的 ID。我正在从 Lead 获取 Id 和浏览数据,即 Browsing_History__c。
我是否需要创建一个新对象来保存它然后插入?
trigger ConvertLead on Lead (after update)
{
if (Trigger.new.size() == 1)
{
if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true)
{
// if a new contact was created
if (Trigger.new[0].ConvertedContactId != null)
{
for(Web_Browsing__c wb_old : [Select Id, Browsing_History__c from Web_Browsing__c where Lead__c= :Trigger.new[0].id])
{
Web_Browsing__c wb = new Web_Browsing__c();
wb.Contact__c = Trigger.new[0].ConvertedContactId;
//Get browsing data
insert wb;
}
}
}
}
}
I have some leads which have a custom browsing activity object which stores the links they browse through. When I convert a lead to a contact, everything except the custom object gets transferred over. Is there a way to import that custom object with the data after conversion either through triggers or c# code?
Any help would be appreciated. Thanks
Thank you for your response.
This is what I have so far. I am unable to get the browsing data; it only gets the ID related to that activity. I am getting the Id and browsing data which is the Browsing_History__c from the Lead.
Do I need to create a new object to hold it and then insert?
trigger ConvertLead on Lead (after update)
{
if (Trigger.new.size() == 1)
{
if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true)
{
// if a new contact was created
if (Trigger.new[0].ConvertedContactId != null)
{
for(Web_Browsing__c wb_old : [Select Id, Browsing_History__c from Web_Browsing__c where Lead__c= :Trigger.new[0].id])
{
Web_Browsing__c wb = new Web_Browsing__c();
wb.Contact__c = Trigger.new[0].ConvertedContactId;
//Get browsing data
insert wb;
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
肯定有,但我不确定为什么你会在这个上采用 C# 路径。您可以避免使用 Force.com/REST API,因为 Apex 触发器在这里完全有能力。
因此,在更新后的潜在客户触发器中,请确保您的trigger.new.IsConverted == true && trigger.old.IsConverted == false(表明这是一个新的转换),将这些主要对象添加到后处理列表中。
然后对这些相关的自定义对象 ID 使用 SOQL 来更新或传输数据。
另外,如果您是 Apex 新手,我会在 Apex 开发指南中搜索 Bulkify,以解决一些令人头疼的问题。
干杯,
亚当
There definitely is, but I'm not sure why you would take the C# path on this one. You can avoid the Force.com/REST API since Apex triggers are perfectly capable here.
So in a Lead after update trigger, making sure your trigger.new.IsConverted == true && trigger.old.IsConverted == false (showing this to be a fresh conversion), add those lead objects to a post-processing list.
Then use SOQL on those related custom object Ids to either update or transfer your data.
Also, if you're new to Apex I'd search the Apex dev guide for Bulkify to save some trigger-headaches.
Cheers,
Adam
是的,这可以使用 Process Builder 或 Apex 触发器来实现。
我的博客上有分步说明和屏幕截图:https://douglascayers.wordpress.com/2016/05/29/salesforce-preserve-lated-lists-and-chatter-on-lead-conversion/。我在下面回顾了这个想法的要点。
将另一个自定义查找字段添加到帐户、联系人和/或
机会。 (我们将从
潜在客户的
ConvertedAccountId
、ConvertedContactId
或转换时的
ConvertedOpportunityId
字段)。IsConverted
字段是否变为TRUE
。ConvertedAccountId
、ConvertedContactId
或ConvertedOpportunityId
字段分配给对象上相应的自定义查找字段。Yes, this is possible using Process Builder or Apex Triggers.
I have step by step instructions and screen shots on my blog: https://douglascayers.wordpress.com/2016/05/29/salesforce-preserve-related-lists-and-chatter-on-lead-conversion/. I've recapped the gist of the idea below.
add another custom lookup field to Account, Contact, and/or
Opportunity. (We will populate one or more of these fields from the
lead's
ConvertedAccountId
,ConvertedContactId
, orConvertedOpportunityId
fields upon conversion).IsConverted
field becameTRUE
.ConvertedAccountId
,ConvertedContactId
, orConvertedOpportunityId
field to the respective custom lookup field on your object.