Triggers 尝试生成rollup apex触发器时发生编译错误

Triggers 尝试生成rollup apex触发器时发生编译错误,triggers,aggregate,rollup,Triggers,Aggregate,Rollup,我一直在修改一段代码以满足我的需要,但它无法编译。我天真的眼睛看不到我行为的错误: trigger doRollup on Time_Record__c (after insert, after update, after delete, after undelete) { // List of parent record ids to update Set<Id> parentIds = new Set<Id>(); // In-memory copy of

我一直在修改一段代码以满足我的需要,但它无法编译。我天真的眼睛看不到我行为的错误:

trigger doRollup on Time_Record__c (after insert, after update, after delete, after     undelete) {

// List of parent record ids to update
Set<Id> parentIds = new Set<Id>();

// In-memory copy of parent records
Map<Id,Time_Record__c> parentRecords = new Map<Id,Time_Record__c>();

// Gather the list of ID values to query on
for(Daily_Time_Record__c c:Trigger.isDelete?Trigger.old:Trigger.new)
parentIds.add(c.Time_Record_Link__c);

// Avoid null ID values
parentIds.remove(null);

// Create in-memory copy of parents
for(Id parentId:parentIds)
parentRecords.put(parentId,new Time_Record__c(Id=parentId,RollupTarget__c=0));

// Query all children for all parents, update Rollup Field value
for(Daily_Time_Record__c c:[select id,FieldToRoll__c,Time_Record_Link__c from Daily_Time_Record__c where id in :parentIds])
parentRecords.get(c.Time_Record_Link__c).RollupTarget__c += c.FieldToRoll__c;

// Commit changes to the database

Database.update(parentRecords.values());
}
trigger doRollup on Time\u Record\u\c(插入后、更新后、删除后、取消删除后){
//要更新的父记录ID的列表
Set parentId=new Set();
//父记录的内存中副本
Map parentRecords=new Map();
//收集要查询的ID值列表
用于(每日时间记录c:Trigger.isDelete?Trigger.old:Trigger.new)
添加(c.Time\u Record\u Link\u c);
//避免空ID值
parentId.remove(null);
//在内存中创建父级的副本
用于(Id parentId:parentId)
parentRecords.put(parentId,新时间记录(Id=parentId,RollupTarget=0));
//查询所有父项的所有子项,更新汇总字段值
对于(每日时间记录c:[从每日时间记录c中选择id、字段集合c、时间记录链接c,其中id位于:ParentID])
parentRecords.get(c.Time\u Record\u Link\u c).RollupTarget\u c+=c.FieldToRoll\u c;
//将更改提交到数据库
Database.update(parentRecords.values());
}
其中:

  • 时间是我的父母
  • RollUpTarget_u_______________________________
  • 每天的时间记录就是孩子
  • Time_Record_Link___c是指向子系统上存在的父系统的链接
  • FieldToRoll_;c是一个在孩子身上卷起的测试场
我认为这就是我必须从这个通用模板中替换的内容:

trigger doRollup on Child__c (after insert, after update, after delete, after undelete) {
// List of parent record ids to update
Set<Id> parentIds = new Set<Id>();
// In-memory copy of parent records
Map<Id,Parent__c> parentRecords = new Map<Id,Parent__c>();
// Gather the list of ID values to query on
for(Child__c c:Trigger.isDelete?Trigger.old:Trigger.new)
  parentIds.add(c.ParentField__c);
// Avoid null ID values
parentIds.remove(null);
// Create in-memory copy of parents
for(Id parentId:parentIds)
  parentRecords.put(parentId,new Parent__c(Id=parentId,RollupField__c=0));
// Query all children for all parents, update Rollup Field value
for(Child__c c:[select id,Amount__c,ParentField__c from Child__c where id in :parentIds])
  parentRecords.get(c.ParentField__c).RollupField__c += c.Amount__c;
// Commit changes to the database
Database.update(parentRecords.values());
  }
在子对象上触发doRollup(插入后、更新后、删除后、取消删除后){
//要更新的父记录ID的列表
Set parentId=new Set();
//父记录的内存中副本
Map parentRecords=new Map();
//收集要查询的ID值列表
for(Child\uuu c:Trigger.isDelete?Trigger.old:Trigger.new)
parentId.add(c.ParentField\uuu\c);
//避免空ID值
parentId.remove(null);
//在内存中创建父级的副本
用于(Id parentId:parentId)
parentRecords.put(parentId,新的Parent__c(Id=parentId,RollupField__c=0));
//查询所有父项的所有子项,更新汇总字段值
对于(子项c:[从子项c中选择id、金额c、父项字段c,其中id位于:父项id])
parentRecords.get(c.ParentField\uuuu c).RollupField\uu c+=c.Amount\uu c;
//将更改提交到数据库
Database.update(parentRecords.values());
}

理想情况下,我希望从子级汇总7个字段的总和(因此需要此解决方案),但从小开始。

触发器应该在子级上,而不是在父级上。它现在可以保存,但实际上什么都不做。我们只能想象最后的SoQL没有得到任何改变。虽然我无法想象如何排除故障。是的。where-id in:parentIds]应该是Time\u-Record\u-Link\u\c in:parentIds]需要做一些测试的地方,但应该就是这样。