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
eblaxtoneblaxton 

Trigger on activity custom field

Hi and thanks in advance for your help.

I have created a custom activity field (Time zone) and it is available to both tasks and events.  I want the time zone field to retain the value for the time zone field on subsequent task and events added.

For example, an event/ task is added to a lead and a timezone is chosen.  The agent then hits the save and add new event, I want the Timezone field to contain the value from the first event/task.

Thank you
sandeep1989sandeep1989

write a trigger on the event object which retrieves one of the event associated to the lead object and populate it while saving.

eblaxtoneblaxton
Hi,

Thanks for your response. I am new to Apex and could use your help in writing this simple trigger. Can you help out?

Regards,
Eric
sandeep1989sandeep1989

trigger triggerEvent on Event (before insert, before update) {
map<string,list<string>> eventleadids = new map<string,string>();
for(Event e : trigger.new)
{
if(e.whatid == null)
{
list<string> ids = new list<string>();
if(eventleadids.containskey(e.whoid))
ids = eventleadids.get(e.whoid)
ids.add(e.id)
eventleadids.add(e.whoid,ids)
}
}
for(lead l : [select id,(select id,time_zone__c from events) from lead where l.id in:eventleadids.values()]
{
if(l.events.size()>0)
{
list<event> events = l.events;
for(string id :eventleadids.get(l.id))
{
trigger.newmap.get(id).time_zone__c = events[0].time_Zone__c;
}
}
}
}

 

 

hope this helps.