hi, try this:
If it solves your issue please mark as correct so it can help others asking the same.Good luck!trigger updateCampaignStatus on Campaign_Follow_Up_Stage__c (after Update,after insert) {
set<Id> campIds = new set<Id>();
Map<Id,String> statusByIdMap = new Map<Id,String>();
for(Campaign_Follow_Up_Stage__c c : trigger.new){
if(c.Status__c == 'Planned' || c.Status__c == 'Draft' || c.Status__c == 'Compelete'){
campIds.add(c.id);
statusByIdMap.put(c.id,c.Status__c );
}
}
List<Campaign> cmList = [SELECT id, status FROM Campaign WHERE id In :campIds];
for(Campaign cm : cmList){
if(statusByIdMap.get(cm.id) == 'Planned'){
cm.status = 'In Progress';
}
if(statusByIdMap.get(cm.id) == 'Draft'){
cm.status = 'Planned';
}
if(statusByIdMap.get(cm.id) == 'Compelete'){
cm.status = 'Compelete';
}
}
update cmList;
}
2 answers