1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public without Sharing class CampaignTriggerClass { public Static void routineAfterInsert(List<Campaign> triggerNew ){ List <CampaignMemberStatus> CMSDeleteList = new List<CampaignMemberStatus>(); for (CampaignMemberStatus cms: [SELECT id, CampaignID, HasResponded, IsDefault, Label, SortOrder FROM CampaignMemberStatus WHERE CampaignID in :triggerNew]){ CMSDeleteList.add(cms); } List <CampaignMemberStatus> CMSList = new List<CampaignMemberStatus>(); for (Campaign c :triggerNew){ CMSList.addAll(GenMemberStatusList(c.id)); } insert CMSList; delete CMSDeleteList; } public static List <CampaignMemberStatus> GenMemberStatusList(string cid){ List <CampaignMemberStatus> NewStatuses = new List<CampaignMemberStatus>(); CampaignMemberStatus c1 = new CampaignMemberStatus(CampaignID = cid, Label = 'To be Invited', IsDefault = true, HasResponded = true, SortOrder = 3); CampaignMemberStatus c2 = new CampaignMemberStatus(CampaignID = cid, Label = 'Invited', IsDefault = false, HasResponded = false, SortOrder = 4); CampaignMemberStatus c3 = new CampaignMemberStatus(CampaignID = cid, Label = 'Confirmed', IsDefault = false, HasResponded = false, SortOrder = 5); CampaignMemberStatus c4 = new CampaignMemberStatus(CampaignID = cid, Label = 'Attended', IsDefault = false, HasResponded = false, SortOrder = 6); NewStatuses.add(c1); NewStatuses.add(c2); NewStatuses.add(c3); NewStatuses.add(c4); return NewStatuses; } }
|