function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jojo10jojo10 

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

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney

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

Ritesh AswaneyRitesh Aswaney

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;

 

}

 

This was selected as the best answer
jojo10jojo10

Thank You!!

 

Really appreciate the answer, and the code! Works perfectly.

 

Jo