LoginSignup
0
1

More than 1 year has passed since last update.

関連するレコードを結びつけたい

Last updated at Posted at 2022-09-15

フローで関連するレコードを結びつけたい

ApexだとMap<Id,List<Contact>> というちょっと変わった変数を使って簡単にできそうです。
フローだと20個の分岐が必要みたい。 やっぱりApexの方が簡単だと思うな。
trigger xxxxxTrigger on Account (Before insert,Before update) {

   Set<Id> AccountSetId = new Set<Id>();

   for (Account acc : Trigger.new){
      AccountSetId.add(acc.Id);
   }
   List<Contact> conList =[SELECT Id,AccountId FROM Contact WHERE AccountId =: AccountSetId Order by AccountId,Id];
   String key_Id = '';
   Integr I = 0;
   Map<Id,List<Id>> conMap = new Map<Id,List<Id>>();
   for (Contact con : conList){
     if (I == 0 ) {
          key_Id = con.AccountId;
          List<Id> conIdList = new List<Id>();
     }
     if ( ke_Id == c.AccountId) {
        conIdList.add(con.Id);
     } else {
        conMap.put(con.AccountId,conIdList);
        key_Id = con.AccountId;
        List<Id> conIdList = new List<Id>();
        conIdList.add(con.Id);
     } 
     I = I + 1;
   }
   conMap.put(con.AccountId,conIdList);
  
   for (Account acc : Trigger.new){
      List<Id> IdList = (List<Id>)conMap.get(acc.Id);
      if (IdList !=null) {
         Integer max = IdList.size();
         for (Integer i = 0, i < max; i++) {
           if (i ==0) acc.1件目 = IdList[i];
           if (i ==1) acc.2件目 = IdList[i];
           if (i ==2) acc.3件目 = IdList[i];
           if (i ==3) acc.4件目 = IdList[i];
           if (i ==4) acc.5件目 = IdList[i];
           if (i ==5) acc.6件目 = IdList[i];
           if (i ==6) acc.7件目 = IdList[i];
           if (i ==7) acc.8件目 = IdList[i];
           if (i ==8) acc.9件目 = IdList[i];
           if (i ==9) acc.10件目 = IdList[i];
           if (i ==10) acc.11件目 = IdList[i];
           if (i ==11) acc.12件目 = IdList[i];
           if (i ==12) acc.13件目 = IdList[i];
           if (i ==13) acc.14件目 = IdList[i];
           if (i ==14) acc.15件目 = IdList[i];
           if (i ==15) acc.16件目 = IdList[i];
           if (i ==16) acc.17件目 = IdList[i];
           if (i ==17) acc.18件目 = IdList[i];
           if (i ==18) acc.19件目 = IdList[i];
           if (i ==19) acc.20件目 = IdList[i];
         }
      }
   }

}
   
}

image.png
 

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1