You need to sign in to do that
Don't have an account?
jojo10
Displaying Mobile number on Event
Hi,
I want to display the Contact's mobile number on my Event. I am not able to use a cross-object formula as the Contact lookup is not available.
Any ideas how I can achieve this? Ideally no Apex.
Thanks
The WhoId and WhatId Lookups on Activities (Tasks and Events) are Polymorphic, i.e. WhoId can point to a Contact or User Or ... and WhatId can point to an Account / Opportunity, i.e. there is no way to tell which specific object the reference is a look up to.
Therefore Cross Object formula's will not be possible.
An Apex Trigger on Event is the only plausible solution - should be simple enought.
trigger EventBeforeTrigger on Event(before insert)
{
Id[] contacts = new Id[]{};
for(Event evt : trigger.New)
if(evt.WhoId != null)
contacts.add(evt.WhoId);
Map<Id,Contact> contactsMap = new Map<Id, Contact> ([Select Id, Name, MobilePhone from Contact where Id in :contacts]);
for(Event evt : trigger.New)
if(evt.WhoId != null)
evt.ContactMobilePhone__c = contactsMap.get(evt.WhoId).MobilePhone;
}
All Answers
The WhoId and WhatId Lookups on Activities (Tasks and Events) are Polymorphic, i.e. WhoId can point to a Contact or User Or ... and WhatId can point to an Account / Opportunity, i.e. there is no way to tell which specific object the reference is a look up to.
Therefore Cross Object formula's will not be possible.
An Apex Trigger on Event is the only plausible solution - should be simple enought.
trigger EventBeforeTrigger on Event(before insert)
{
Id[] contacts = new Id[]{};
for(Event evt : trigger.New)
if(evt.WhoId != null)
contacts.add(evt.WhoId);
Map<Id,Contact> contactsMap = new Map<Id, Contact> ([Select Id, Name, MobilePhone from Contact where Id in :contacts]);
for(Event evt : trigger.New)
if(evt.WhoId != null)
evt.ContactMobilePhone__c = contactsMap.get(evt.WhoId).MobilePhone;
}
Thank You!!
Really appreciate the answer, and the code! Works perfectly.
Jo