SHARE
TWEET

Untitled

a guest Jan 12th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class UpdateDetailClass {
  2.  
  3.     public static void UpdateDetailMethod(List<Master__c> masterList) {
  4.  
  5.         Set<Id> masterIds = new Set<Id>();
  6.  
  7.         for(Master__c master : masterList) {
  8.             masterIds.add(master.Id);  
  9.         }
  10.  
  11.         List<Detail__c> detailList = new List<Detail__c>([SELECT Id, Master__c, Master__r.isSelected__c, Type__c FROM Detail__c WHERE Master__c IN: masterIds]);
  12.  
  13.         List<Detail__c> detailToUpdate = new List<Detail__c>();
  14.  
  15.         for(Master__c master : masterList) {
  16.  
  17.             for(Detail__c d : detailList) {
  18.                 if(master.Id != null) {
  19.                     if(master.isSelected__c == true) {
  20.                         d.Master__c = master.Id;
  21.                         d.Type__c = master.Type__c;
  22.                         detailToUpdate.add(d);
  23.                     }    
  24.                 }    
  25.             }
  26.  
  27.         }
  28.  
  29.         update detailToUpdate;    
  30.  
  31.     }
  32.  
  33. }
  34.    
  35. trigger updateTrigger on Master__c (after update) {
  36.     if(Trigger.isAfter && Trigger.isUpdate) {
  37.         UpdateDetailClass.UpdateDetailMethod(Trigger.New);
  38.     }  
  39. }
RAW Paste Data
Top