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
Starz26Starz26 

Trigger Update event - how to "Save and Send updates" via the trigger

Simply updating the event does not send out the invites. Is there a way via apex to send updates to attendees when an event is updated?

Starz26Starz26

Anyone have any ideas on how to send the standard notify attendees email via apex code?

AsiereikiAsiereiki

I want to know too

Hazee.LiHazee.Li
Anyone found a solution for this or thic cannot be done?

http://salesforce.stackexchange.com/questions/88589/trigger-the-event-save-and-send-update-email-with-apex
Amrin PattekariAmrin Pattekari

Hi,

I have written a trigger for sending a update notification whenever an event is updated. Please let me know if this helps.

Please find below the trigger:
 
trigger SendNotificationToAttendees on Event(after update) 
{
    if(Trigger.isAfter && Trigger.isUpdate)
    {
        List<EventRelation> relationEventList=new List<EventRelation>([SELECT RelationId, EventId FROM EventRelation WHERE EventId IN: Trigger.newMap.keySet()]);
        
        Map<Id, EventRelation> relationIdAndEventRelationMap=new Map<Id, EventRelation>();
        for(EventRelation relationRecord: relationEventList)
        {
            relationIdAndEventRelationMap.put(relationRecord.RelationId, relationRecord);
        }
        
        Map<Id, Lead> leadMap=new Map<Id, Lead>([SELECT Id, Email FROM Lead WHERE Id IN: relationIdAndEventRelationMap.keySet()]);
        
        Map<Id, Contact> contactMap=new Map<Id, Contact>([SELECT Id, Email FROM Contact WHERE Id IN: relationIdAndEventRelationMap.keySet()]);
        
        Map<Id, User> userMap=new Map<Id, User>([SELECT Id, Email FROM User WHERE Id IN: relationIdAndEventRelationMap.keySet()]);
        
        List<Messaging.SingleEmailMessage> singleEmailMessagesList=new List<Messaging.SingleEmailMessage>();
        
        for(Event eventRecord: Trigger.New)
        {
            List<String> emailIdsList=new List<String>();
            
            for(Integer i=0; i<(new List<Id>(relationIdAndEventRelationMap.keySet())).size(); i++)
            {
                if(eventRecord.Id==relationIdAndEventRelationMap.values()[i].EventId)
                {
                    //For Leads.
                    for(Integer j=0; j<(new List<Id>(leadMap.keySet())).size(); j++)
                    {
                        if((new List<Id>(relationIdAndEventRelationMap.keySet()))[i]==(new List<Id>(leadMap.keySet()))[j])
                        {
                            emailIdsList.add(leadMap.values()[j].Email);
                        }
                    }
                    
                    //For Contacts.
                    for(Integer j=0; j<(new List<Id>(contactMap.keySet())).size(); j++)
                    {
                        if((new List<Id>(relationIdAndEventRelationMap.keySet()))[i]==(new List<Id>(contactMap.keySet()))[j])
                        {
                            emailIdsList.add(contactMap.values()[j].Email);
                        }
                    }
                    
                    //For Users.
                    for(Integer j=0; j<(new List<Id>(userMap.keySet())).size(); j++)
                    {
                        if((new List<Id>(relationIdAndEventRelationMap.keySet()))[i]==(new List<Id>(userMap.keySet()))[j])
                        {
                            emailIdsList.add(userMap.values()[j].Email);
                        }
                    }
                }
            }
            
            Messaging.SingleEmailMessage singleEmail=new Messaging.SingleEmailMessage();
            singleEmail.setToAddresses(emailIdsList);
            singleEmail.setSubject(eventRecord.Subject);
            singleEmail.setPlainTextBody(eventRecord.Description);
            singleEmailMessagesList.add(singleEmail);
        }
        
        //send mail
        Messaging.sendEmail(singleEmailMessagesList);
    }
}



Thanks,
Amrin