【发布时间】:2014-02-12 19:59:52
【问题描述】:
当与此客户相关的联系人更改字段时,如何创建触发器以更新客户上的字段。
示例--- 如果联系人有邮寄城市,则相应的帐户邮寄城市字段应更新为相同的值
我的触发器如下
但它不起作用 从 Schema.SObjectField 到 String 的非法赋值
我写的代码也是来自google。我无法解决这个问题。请帮忙
trigger ContactToAccountAddress on Contact (after insert,after update) {
List<ID> AccID = New List<ID>();
for(Contact con : Trigger.new){
if(con.MailingCity!=null&& con.AccountId != null){
AccID.add(con.AccountId);
}
}
List<Account> accList = [SELECT Name, BillingStreet FROM Account WHERE id in :AccID];
for(integer i = 0 ; i < accList.size(); i++){
accList[i].BillingStreet =Contact.MailingCity;
}
update accList;
}
【问题讨论】:
标签: triggers salesforce apex-code