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
dfiorentdfiorent 

Creating a trigger on Event to update an Event custom field with a value from Contact

I am trying to write a trigger on Event what will update a custom field on Event with a value from the Contact. (We want to capture the value in this field at the time of the call).    I thought that this would be fairly easy, but I am having difficulties.  Has anyone done something similar?

 

Any help would be greatly appreciated!

SurekaSureka

Hi,

 

The below code might help you.

 

trigger UpdateContact on Event (before insert, before update) {
for(Event e:trigger.new)
{
Contact c= [select Id, Name from Contact where id=:e.whoId];
e.CustomFeild__c = c.Name;
}
}

 

This is just a sample trigger. This will not work if you are doing bulk uploads. You need to enhance it.

 

Thanks

dfiorentdfiorent

Thank you so much!  I was making it much more complicated that it needed to be.