使用定期捐款更新相关的机会记录,以找到它的兄弟姐妹

时间:2017-12-26 15:35:37

标签: triggers apex-code apex

我在以下参数中编码:

  • 经常性捐赠和机会通过Lookup相关(不是 主详细)。
  • 经常性捐赠可以有多种机会 与之相关。
  • 机会只能与一个重复发生有关 捐款。
  • 任何经常性捐赠都没有查询字段 相关的机会。
  • 机会上有一个查找字段 链接到经常性捐赠。
  • 填充第一个商机 拥有最新的信用卡信息。
  • 此信息 需要复制到重复出现的下一个机会 两个机会之间的捐赠记录是一样的。
  • 这些是加密字段,否则我会使用Process Builder或Flow。

以下是我认为可行的方法,但我收到错误:

Error: Compile Error: Method does not exist or incorrect signature: void add(String) from the type List<Opportunity> at line 27 column 17   

trigger putCConRD on Opportunity (after update){

List<Opportunity> oppRecords = new List<Opportunity>();
//List<npe03__Recurring_Donation__c> rdRecords = new List<npe03__Recurring_Donation__c>();
Set<ID> associatedRDids = new Set<ID>();

List<Opportunity> oppToUpdate = new List<Opportunity>();

//For every new version of an opportunity record, add their related recurring donation to the associated Rds list. 
for(Opportunity Opp : Trigger.new){
    associatedRDids.add(Opp.npe03__Recurring_Donation__c);
    }

oppRecords = [Select Id, ChargentSFA__Card_Month__c, ChargentSFA__Card_Year__c, ChargentSFA__Card_Number__c, ChargentSFA__Card_Security__c from Opportunity where Id in :associatedRDids];
//now we should have a list of opportunity records that are associated with the recurring donations. 

//now to find the most recent close won opportunity related to that recurring donation
List<Opportunity> mostRecent = new List<Opportunity>([Select Id, ChargentSFA__Card_Month__c, ChargentSFA__Card_Year__c, ChargentSFA__Card_Number__c, ChargentSFA__Card_Security__c from Opportunity order by createdDate desc limit 1]);

for(Opportunity Opp2: oppRecords){

    Opp2.ChargentSFA__Card_Month__c = mostRecent[0].ChargentSFA__Card_Month__c;   
    Opp2.ChargentSFA__Card_Year__c = mostRecent[0].ChargentSFA__Card_Year__c;
    Opp2.ChargentSFA__Card_Number__c = mostRecent[0].ChargentSFA__Card_Number__c;
    Opp2.ChargentSFA__Card_Security__c = mostRecent[0].ChargentSFA__Card_Security__c;

    oppToUpdate.add(Opp2.ChargentSFA__Card_Month__c);
    oppToUpdate.add(Opp2.Opp2.ChargentSFA__Card_Year__c);
    oppToUpdate.add(Opp2.Opp2.ChargentSFA__Card_Number__c);
    oppToUpdate.add(Opp2.Opp2.ChargentSFA__Card_Security__c);
}

update OpptoUpdate;

}

有人可以帮我弄清楚我哪里出错了吗?即使不是代码,也要感谢一些设计指导。试图将我的顶点理解扩展到基本触发之外。

0 个答案:

没有答案