0

The user can select a group of Contacts. At that point we create a single new Event, as well as, an EventRelation for each Contact (marked as an Invitee)

That is done through a controller extension (see code below) and seems to generate all the objects perfectly. The problem is I don't know why the Event doesn't show up in the 'Activity History for the Invitee.

We have 'shared activities' enabled for the organization and no errors or issues appear in the log.


public with sharing class CreateEvent_Controller
{
    public Event eventNew {get; set;} 
    public List<Contact> selectedContacts { get; set; }  

    public CreateEvent_Controller(ApexPages.StandardSetController controller) 
    {
        selectedContacts = [select id, Name from Contact where id IN :((List<Contact>)controller.getSelected())];
        eventNew = new Event();
        eventNew.OwnerId = UserInfo.getUserId(); //Assigned To
        eventNew.GroupEventType = 2;
        eventNew.IsAllDayEvent = true;
        eventNew.IsGroupEvent = true;

        if(selectedContacts.isEmpty() == true)
        {
            ApexPages.Message noContactsSelected = new ApexPages.Message(ApexPages.Severity.INFO, 'No Contact Records Selected: Press The Cancel Button To Return To The Contacts Page To Select Contacts');
            ApexPages.addMessage(noContactsSelected);
        }

    }

    public PageReference SaveEvent() 
    {                       
        Database.saveresult eventInsertResult = database.insert(eventNew); 
        if(eventInsertResult.isSuccess())
        {
            List<EventRelation> contactEventLinks = new List<EventRelation>();

            for(Contact ct: selectedContacts)
            {
                EventRelation newLink = new EventRelation(EventId=eventNew.ID, RelationId=ct.ID, Status='Accepted', IsInvitee=true);
                contactEventLinks.add(newLink);
            }

            if (contactEventLinks.size() > 0)
            {
                try
                {
                    insert contactEventLinks;
                }
                catch (Exception e)
                {
                    delete eventNew;
                }
            }
        }

        PageReference pageRef = new PageReference(' HIDDEN FOR DEMO ');
        pageRef.setRedirect(true);
        return pageRef;          
    }

}

1 Answer 1

0

There are 3 properties of EventRelation that need to be set correctly for the Event to appear in the Activity History of each Invitee.

  • IsInvitee = true - Needed to have the Contact automatically accept the Event
  • IsParent = true - Needed to correctly appear in the Activity History
  • IsWhat = false - Needed to correctly appear in the Activity History

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.