You need to sign in to do that
Don't have an account?
ForceRookie
Update parent record based on child’s field
On update of Parent Campaign, it will check it’s Child Campaign that has Monitoring RecordType. If Do_Not_Notify_Subscriber__c = True, then update Parent Campaign Do_Not_Notify_Subscriber__c = True.
But I’m getting Duplicate id in list.. what’s wrong with my code?
But I’m getting Duplicate id in list.. what’s wrong with my code?
public class UpdateParentCampaignHandler implements TriggerHandlerInterface { public static void updateParentCampaign(List<Campaign__c> scope) { String RecordTypeIdMon = Schema.SObjectType.Campaign__c.getRecordTypeInfosByName().get('Monitoring').getRecordTypeId(); Set<Id> parentIds = new Set<Id>(); for (Campaign__c c : scope) { parentIds.add(c.Id); } List<Campaign__c> cList = new List<Campaign__c>(); if (!parentIds.isEmpty()) { List<Campaign__c> parentCamp = [SELECT Id, Do_Not_Notify_Subscriber__c FROM Campaign__c WHERE Id IN :parentIds]; List<Campaign__c> allCamps = [SELECT Id, Parent_Campaign__c, RecordTypeId, Do_Not_Notify_Subscriber__c FROM Campaign__c WHERE Parent_Campaign__c IN :parentIds AND RecordTypeId =: RecordTypeIdMon]; for (Campaign__c parentCampaign : parentCamp) { for (Campaign__c childCampaign : allCamps) { if (childCampaign.Do_Not_Notify_Subscriber__cDo_Not_Notify_Subscriber__c = True) { parentCampaign.Do_Not_Notify_Subscriber__c = True; cList.add(parentCampaign); } } } update cList; } } }
-
- can u remove 2 soql and make one
- looks like your trigger is firing recursively
refer this link for how to avoid recursivehttps://help.salesforce.com/articleView?amp;language=en_US&id=000199485&type=1
All Answers
But i guess the code whihc you shared is not complete
-
- can u remove 2 soql and make one
- looks like your trigger is firing recursively
refer this link for how to avoid recursivehttps://help.salesforce.com/articleView?amp;language=en_US&id=000199485&type=1