You need to sign in to do that
Don't have an account?
Event field to Campaign Field Trigger
I am trying to pull a custom field in an event into a custom field in the campaign that the event is related to. The trigger seems to be saving without any errors but it's not working the way I would expect it to. The code I'm using is:
trigger SetiLinkURLinCampaign on Campaign (before insert, before update){
Campaign[] triggerBatch = Trigger.new;
// List of Campaign IDs
List<String> cmpgnIDs = new List<String>();
for(Campaign c:triggerBatch){
cmpgnIDs.add(c.id); // Adding CampaignId to List
}
// Event Map
Map<ID, Event> eventMap = new Map<ID, Event>([select id, OwnerId, ILNC_sf__iLincJoinURL__c from Event where Id = :cmpgnIDs]);
for(Campaign c:triggerBatch){
if(eventMap.containsKey(c.Id)){
Event campaign = eventMap.get(c.Id) ;
c.iLinc_Join_URL__C = campaign.ILNC_sf__iLincJoinURL__c;
}
}
}
Any help would be greatly appriciated.
Thanks,
Sean
I'm guessing that there is a Campaign Custom Lookup field on the Event Object, ie. Event looks up to Campaign
The first bit of your code seems arlight ....
// Event Map
Map<Id, Event> campEvtMap = new Map<Id, Event>{};
for (Event ev : [select id, OwnerId, ILNC_sf__iLincJoinURL__c from Event where CampaignId__c IN :cmpgnIDs])
campEvtMap.put(ev.CampaignId__c, ev);
for(Campaign c:triggerBatch){
if(campEvtMap.containsKey(c.Id)){
Event campaignEvent = eventMap.get(c.Id) ;
c.iLinc_Join_URL__C = campaignEvent.ILNC_sf__iLincJoinURL__c;
}
}
}
To me also Map does not seems correct as it has event id as key and contains key method check for campaign id but one more point that this trigger is called on before insert also so how could any event have campaignid in lookup before campaign itself is not inserted. Please chcek that also.