Salesforce中使用Personal Account的相关经验汇总(Admin + Developer - Apex Trigger)

前言】:

早前接触到Personal Account的时候仅仅认识到Enable Personal Account后,从Account Tab创建Account时就多了一个Personal Account的记录类型,同时创建一条Personal Account记录后随之copy了一份记录到Contact,如果在任意端Account/Contact改了这个Personal Account,两边信息都是同步的

问题】:

基于提到的上文你可能产生与我相同的疑问:既然Personal Account里面有内部同步机制确保Account和Contact对像记录是一样的,那么我是不是在任意一个对象上写一个Trigger就能保证两个对象都有相同的效果呢?

解惑】:

1. Business Case:
假如需求是这样的:如果Personal Account的Email里面包含test文本,我们就将改Email值变为invalid@email.com;

2. Test Case1:在Account上写一个Trigger如下:

trigger TestAccountTrigger on Account(before insert, before update) {
  for(Account acc : (List<Account>)Trigger.New) {
    if(acc.PersonEmail.contains('test')) {
      acc.PersonEmail = 'invalid@email.com';
    }
  }
}

我们先注释Code片段,创建一条如下记录,会观察到两条记录页面布局都一样,区别是:
a、ID不同,一个前缀是001(Account),一个是003(Contact);
b、如果我们从第二幅图中点击右边的View Fields,此时打开的对象是Account Fields,而非Contact Fields


随后我们解注刚注释掉的Trigger片段,再次在任意端修改记录,会发现两边记录依然保持同步。

3. Test Case2:在Contact上写一个Trigger如下:

trigger TestContactTrigger on Contact(before insert, before update) {
  for(Contact con : (List<Contact>)Trigger.New) {
    if(con.Email.contains('test')) {
      con.Email = 'invalid@email.com';
    }
  }
}

这时我们先将Email改成不包含test的任意Email格式文本,随后再重新编辑为包含test文本的Email,你会发现,你在Contac上写的Trigger没生效

4. 上面的内容咱们先放一放,先看一下下边这个图,来增加你对Personal Account的神秘感:


你不难发现神奇的是,用API Name查看插件显示的Email和Phone竟然不一样!!!

总结】:

1. 对于Personal Account标准字段的同步,Trigger仅需写在Account上即可;
2. Personal Account其实在元数据中是一个包含在Account子节点的标准的单独的对象,一旦开启,会导致Account Fields发生变化,Contact Field无影响,这时Personal Account的记录类型自然会叠加在Account记录类型上;
3. 创建一条Personal Account记录相当于一条记录被不同ID(AccountID / ContactID)所指向;

注意事项】:

1. 截至20年11月11日,无法通过提Case给SF Support的方式开启Person Accounts,详见Idea Details —— Ability to log a case using Developer Org for Support (First Class Citizen)
2. 关于记录合并 - Person accounts can be merged only with other person accounts. You can’t merge person accounts that are enabled as portal or community users;
3. 关于自动化触发 - Creating or editing a person account triggers Process Builder processes. Creating or editing a person account triggers account workflow rules
4. 关于Lead转化 - Leads that don't have a value in the Company field are converted to person accounts. Leads that do have a value in the Company field are converted to business accounts;
5. In Lightning Experience, you can send list emails to person accounts from Contact list views but not Account list views
6. 关于List View - An admin can show which records are person accounts by adding the Is Person Account field to the list of fields to display. To include or exclude person accounts from a list view, add the Is Person Account field to the filter criteria;
7. 关于合并字段 - You can use the merge field {!Account.IsPersonAccount} to determine whether you are working with a person account or a business account;

相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页