Hi Ireed,
Yup the code will work for bulk data, there is a little bit modification with the recordType is needed, See the updated code below
Please have a look on this , I hope this will help.trigger UpdateCampaignMember on Event (before insert) {
Set<Id> campaignId = new Set<Id>();
String Recordtype;
//create a map between record type name and id for easy retrieval
Map<String, String> EventRecordTypes;
List<RecordType> rtypes = [Select Name, Id From RecordType
where sObjectType='Event' and isActive=true];
EventRecordTypes = new Map<String,String>{};
for(RecordType rt: rtypes){
EventRecordTypes.put(rt.Name,rt.Id);
}
//////////////////////////////////////////////////
for(Event e : trigger.new){
String whatId = e.WhatId+'';
Recordtype = e.RecordTypeId;
if(whatId.startsWith('701') && Trigger.isInsert && Recordtype == EventRecordTypes.get('ID INS Event')){
// COLLECTING ALL campaign IDs on which event is created.
// These campaigns are filtered with RecordType
campaignId.add(e.WhatId);
}
}
//IN THE campaignId you have campaign Ids
if(campaignId.size()>0){
// FETCHING ALL Campaign members.
List<campaignMember> cMemberToUpdate = [SELECT id FROM campaignMember WHERE campaignId IN :campaignId];
for(campaignMember cMember : cMemberToUpdate){
cMember.InsCheckIn__c = True;
// UPDATE YOUR CUSTOM FIELD HERE.
}
update cMemberToUpdate;
}
}
7 respuestas