You need to sign in to do that
Don't have an account?
Christine Klein
EventTriggerHandler
When a user clicks on "New Event" from a lead, I would like to populate the campaign field on Events with the campaign that is listed on the Lead Record. I'm running into an error where it says "Variable does not exist: whoid". I can't seem to figure out why it would be complaining about whoid when it shows up under Workbench for events.
public with sharing class EventTriggerHandler { private boolean triggerIsExecuting = false; private integer batchSize = 0; public boolean isTriggerContext{ get { return triggerIsExecuting;} } public boolean isVisualforcePageContext{ get { return !isTriggerContext;} } public boolean isWebServiceContext{ get { return !isTriggerContext;} } public boolean isExecuteAnonymousContext{ get { return !isTriggerContext;} } public EventTriggerHandler(boolean isExecuting, integer size){ triggerIsExecuting = isExecuting; BatchSize = size; } public void UpdateLastCampaignActivityOnEvents(Event[] newEvent) { Set<Id> whoIDs = new Set<ID>(); for(Event CurrentEvent : newEvent) { WhoIds.add(CurrentEvent.whoid); } if (whoIDs.size() > 0 ) { list<Lead> CurrentLeads = [Select ID, Eloqua_Campaign_Name__c From Lead where ID IN :WhoIDs]; map<id,Lead> Leads = new map<id,Lead>(); if (currentLeads.size() > 0 ) { for (Lead currentlead : currentleads) { Leads.put(currentLead.ID, currentLead); } for(Event CurrentEvent : newEvent) { Lead LeadLookup = Leads.get(CurrentEvent.WhoID); if (LeadLookup <> null) { CurrentEvent.Last_Campaign_Activity__c = LeadLookup.Eloqua_Campaign_Name__C; } } } } } public void onBeforeInsert(Event[] newEvent) { UpdateLastCampaignActivityOnEvents(newEvent); } /* @future public static void onAfterInsertAsync(Set<ID> newEventIDs){ } */ /* public void OnAfterInsert(Event[] newEvents) { } */ /* public void onBeforeUpdate(Event[] oldEvent, Event[] updatedEvent, Map<ID, Event> oldEventMap) { } */ /* public void onAfterUpdate(Event[] oldEvent, Event[] updatedEvent, Map<ID, Event> oldEventMap) { } */ /* @future public static void onAfterUpdateAsync(Set<ID> updatedEvent){ } */ /* public void onBeforeDelete(Event[] EventToDelete, Map<ID, Event> EventMap){ } */ /* public void onAfterDelete(Event[] deletedEvent, Map<ID, Event> EventMap){ } */ /* @future public static void onAfterDeleteAsync(Set<ID> deletedEvent){ //to make this work like the on after delete you need to do a select statement into //a list where ID in :deletedOpportunitySplits, this would recreate the deletedOpportunitySplits list //from there the code would work the same. } */ /* public void onUndelete(Event[] restoredEvent){ } */ }
I also optimized your trigger method:
All Answers
I also optimized your trigger method:
I checked the version of my trigger and class and they're both on version 31.
Even with your optimized trigger method I still get the WhoId does not exist error on this line:
mapLeads.put(eve.WhoId, null);
Are you using any IDE for development or using the browser (developer console) for development? Try editing the code in eclipse or developer console and see if it makes a difference. Hope it will resolve your issue.
mapLeads.put(eve.WhoId, null);
and then I got another error on
eve.Last_Campaign_Activity__c = mapLeads.get(eve.WhoId).Eloqua_Campaign_Name__c;
saying Variable Last_Campaign_Activity__c does not exist.I didn't even think to check that as I didn't think Salesforce would let you create a class with the same name as an object. Sigh.
Thanks for all your help!!