Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UpdateDetailClass {
- public static void UpdateDetailMethod(List<Master__c> masterList) {
- Set<Id> masterIds = new Set<Id>();
- for(Master__c master : masterList) {
- masterIds.add(master.Id);
- }
- 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]);
- List<Detail__c> detailToUpdate = new List<Detail__c>();
- for(Master__c master : masterList) {
- for(Detail__c d : detailList) {
- if(master.Id != null) {
- if(master.isSelected__c == true) {
- d.Master__c = master.Id;
- d.Type__c = master.Type__c;
- detailToUpdate.add(d);
- }
- }
- }
- }
- update detailToUpdate;
- }
- }
- trigger updateTrigger on Master__c (after update) {
- if(Trigger.isAfter && Trigger.isUpdate) {
- UpdateDetailClass.UpdateDetailMethod(Trigger.New);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement