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
MikeSFMikeSF 

How to invoke 'Save & Send Update' on Multi-purpose Calendar Event edit in Code

I have a need to be able to recreate the 'Save & Send Update' button functionality on the event screen in APex Code, can anyone help with a code snippet on how to do this please.

Basically I want to have an automated process that monthly creates an 'Event' and then sends out a Meeting invite to all the Invitees.  I particularly want the email functionality that has the 'Respond to This Request' button in the email.

Does anyone know what code is run when the 'Save & Send Update' button is pressed?

Thanks in advance.


Best Answer chosen by MikeSF
MikeSFMikeSF
Thanks for everyone's help, I resolved this in the end by creating the event and relations in my extension controller and the redirecting to the standard Event page.  Pseudo code below, code is executed when user presses a button on my Custome screen, this takes him to The Event edit screen where he can either Save & Send update or Cancel (which returns him to the current screen).  If he cancels then this leaves a spare event lying about, so you need to arrange to zap this.
// Save the event
insert myEvent;

// Also want to create a new EventRelation for the Lead
List<EventRelation> myErs = new List<EventRelation>();
EventRelation myEventRelation = new EventRelation();
.
myEventRelation.EventId = myEvent.Id;
myEventRelation.Status = 'New';
myEventRelation.RelationId = myLead.Id;
myErs.Add(myEventRelation);
// and the manager, as long as he does not own the event
if(myEvent.OwnerId != myLeadOwnerId) {
  myEventRelation = new EventRelation();
  myEventRelation.EventId = myEvent.Id;
  myEventRelation.Status = 'New';
  myEventRelation.RelationId = myLeadOwnerID;
  myErs.Add(myEventRelation);
}
insert myErs;

// Pass control to the standard event create function
ApexPages.StandardController ctrl = new ApexPages.StandardController(myEvent);
PageReference myEventPage = ctrl.edit();

// We want the control to go back to here.  If user cancels (retURL)
PageReference leadPage = Page.myLeadPage;

leadPage.getParameters().put('e_id', myEvent.Id );
leadPage.getParameters().put('id', myLead.Id );
myEventPage.getParameters().put('retURL', leadPAge.getUrl());

// We want the control to go back to here.  If user Saves (saveURL)
PageReference leadListPage = Page.myLeadList;
myEventPage.getParameters().put('saveURL', leadListPage.getUrl());

myEventPage.setRedirect(true);

return myEventPage;

 

All Answers

izay.ramos-irizarry1.3893936724146558E12izay.ramos-irizarry1.3893936724146558E12
Hi Mike,

In you apex code after inserting the event create your event attendees and try setting the Database.DmlOptions triggerUserEmail to true. This may cause the email to be sent to each attendee. Example:

Database.DMLOptions dlo = new Database.DmlOptions();
dlo.EmailHeader.triggerUserEmail = true;
//Insert the attendees using database.insert(attendees list, dmlOption);
database.insert(attendees, dlo);

Hope this helps!
MikeSFMikeSF

Hi Izay,
That has pointed me in the right direction and has gone a long way towards giving me a solution, I have managed to get an invite sent to all Attendees
- since v25 these are now called 'EventRelation', had to use triggerOtherEmail as they were not users. 
However, I still can't get it to send an invite to the Event owner, you cannot add an EventRelation for the Owner as SF quietly deletes it. 
As expected pressing the 'Save and Send Update' on the event screen does invite the owner, so there must be another (as yet unknown) database option to cause this to happen. 

Any ideas on what that might be?

Many thanks for your help so far!
Mike 
 
 

Hemant shuklaHemant shukla
Hi MikeSF,

I am sorry, I dont have the solution for your question. But I have the same requirement to send an email to invitees when they get added via Apex code using EventRelation. I tried with many combination of Dml options but couldn't. Can you please post the code snippet which worked for you?

Many Thanks in advance!
Hemant
Matt McKinleyMatt McKinley
You do it by setting the option on eventRelation:
List<EventRelation> ers = new List<EventRelation>();
ers.add(new EventRelation(eventID='00Ud000000LdBNREA3' ,relationID='003d000001XL0tF'));
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail  = false;
dlo.EmailHeader.triggerOtherEmail  = true;
dlo.EmailHeader.triggerAutoResponseEmail = false;
Database.insert(ers,dlo);
 
MikeSFMikeSF
Thanks for everyone's help, I resolved this in the end by creating the event and relations in my extension controller and the redirecting to the standard Event page.  Pseudo code below, code is executed when user presses a button on my Custome screen, this takes him to The Event edit screen where he can either Save & Send update or Cancel (which returns him to the current screen).  If he cancels then this leaves a spare event lying about, so you need to arrange to zap this.
// Save the event
insert myEvent;

// Also want to create a new EventRelation for the Lead
List<EventRelation> myErs = new List<EventRelation>();
EventRelation myEventRelation = new EventRelation();
.
myEventRelation.EventId = myEvent.Id;
myEventRelation.Status = 'New';
myEventRelation.RelationId = myLead.Id;
myErs.Add(myEventRelation);
// and the manager, as long as he does not own the event
if(myEvent.OwnerId != myLeadOwnerId) {
  myEventRelation = new EventRelation();
  myEventRelation.EventId = myEvent.Id;
  myEventRelation.Status = 'New';
  myEventRelation.RelationId = myLeadOwnerID;
  myErs.Add(myEventRelation);
}
insert myErs;

// Pass control to the standard event create function
ApexPages.StandardController ctrl = new ApexPages.StandardController(myEvent);
PageReference myEventPage = ctrl.edit();

// We want the control to go back to here.  If user cancels (retURL)
PageReference leadPage = Page.myLeadPage;

leadPage.getParameters().put('e_id', myEvent.Id );
leadPage.getParameters().put('id', myLead.Id );
myEventPage.getParameters().put('retURL', leadPAge.getUrl());

// We want the control to go back to here.  If user Saves (saveURL)
PageReference leadListPage = Page.myLeadList;
myEventPage.getParameters().put('saveURL', leadListPage.getUrl());

myEventPage.setRedirect(true);

return myEventPage;

 
This was selected as the best answer
Balu_SFDCBalu_SFDC
Hi MikeSF,

I am facing some exception while inserting the list of EventRealtion rercords,like Con't to bulk insert/upsert on Eventrelation object. In this case how are you inserting bulk EventRelation for a Event? Can you please help?

It would be great if u can share ur working code to my mail balu1211@gmail.com.

Thanks,
​Hussain.