【发布时间】:2020-03-17 19:40:11
【问题描述】:
我尝试编写顶点触发器,但一直失败。当父帐户上的两个字段之一发生更改时,我需要更新联系人上的三个字段。一个字段需要用今天的日期(TODAY())更新,而其他字段需要用父字段的值更新。这是我目前所拥有的。
编辑代码:
trigger UpdateContacts on Acoount (after update){
Set<Id> accountIds = new Set<Id>();
List<Contact> ContactsToUpdate = new List<Contact>();
for (Account account: Trigger.new) {
Account oldaccount = Trigger.oldMap.get(Account.Id);
if (
Account.Beginning_Balance__c != oldaccount.Beginning_Balance__c ||
Account.Ending_Balance__c != oldaccount.Ending_Balance__c ) {
accountIds.add(account.Id); } }
for (Contact contact: [
select Ending_Balance_Date__c,Beginning_Date__c,Today_s_Date__c,
Account_Name__c
from Contact
where Account_Name__c in :accountIds ]) {
contact.Today_s_Date__c = Today();
contact.Ending_Balance_Date__c = Trigger.newMap.get(contact.Account_Name__c).Ending_Balance__c;
contact.Beginning_Date__c = Trigger.newMap.get(contact.Account_Name__c).Beginning_Balance__c;
ContactsToUpdate.add(Contact); }
if (!ContactsToUpdate.isEmpty()) {
update ContactsToUpdate; }
}
您能为我提供的任何帮助将不胜感激。提前谢谢!
【问题讨论】:
标签: triggers salesforce apex