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
iKnowSFDCiKnowSFDC 

Testing Event Trigger - Issue with IsGroupEvent Flag

Hi All,

I'm working on some test code for a trigger that flags a check box is the owner's user role and the invitee user role are part of a list defined in a custom setting. The trigger works as expected, however, when testing the trigger, I am not getting the isGroupEvent flag to populate. I've found several posts around this issue, but the solutions posted have not worked for me. Below is the code, any suggestions would be VERY appreciated.
 
@isTest
private class testEventUpdateTrigger {
    
    private testMethod static void testEventTrigger(){
        //find users with appropriate roles to generate joint meeting flag
        User BHFAUser = [SELECT id, UserRoleId, UserRole.Name FROM User WHERE UserRole.Name = 'Financial Advisor BHFA - Arizona FA' LIMIT 1];
        User preferredUser = [SELECT id, UserRoleId, UserRole.Name FROM User WHERE UserRole.Name = 'Preferred - AZ Premier Bankers' LIMIT 1];
        
        //test 1 - insert an event & verify that the joint meeting flag was set to false.
        system.runAs(BHFAUser){
            Event e1 = new Event(Subject='Test', StartDateTime = date.today(), DurationInMinutes = 60);
            insert e1;
            system.assert(!e1.Joint_Meeting__c);
            
            //Add an Event Relation Record
            EventRelation er1 = new EventRelation(EventId = e1.id, RelationId = preferredUser.id, IsInvitee=true,
                                                 Status='New');
            insert er1;
           	
            e1.Description = 'invited new user';
            update e1;

            system.debug('is group event flag>>>'+e1.IsGroupEvent);
            
            //this assert is failing
            system.assert(e1.Joint_Meeting__c);
            
        }
    }
    

}

 
Hermes Yan 11Hermes Yan 11
I believe you need to re-query the Event back out along with the IsGroupEvent field.
iKnowSFDCiKnowSFDC
Hmmm, still not working.

I added a query before the system.assert but am still failing on the assert. 
Event eventTest = [SELECT id, Joint_Meeting__c, IsGroupEvent FROM Event WHERE id = :e1.id];
            //this assert is failing
            system.assert(eventTest.Joint_Meeting__c);
Hermes Yan 11Hermes Yan 11
In your snippet your asserting that joint_meeting__c is true, but in your code in the first post your asserting that it is false and thats noted in the comments.

 
iKnowSFDCiKnowSFDC
Yes - but once the EventRelation is added, the IsGroupMeeting flag should set to true (it's a read-only field, otherwise I would set it myself).

I confirmed that the once I requery the event, IsGroupMeetting is set to true, however, the trigger is not executiong and setting the joint meeting field to true as it should. 

Is this an issue with creating an EventRelation record via APEX?  I've also tried sending the event to the method directly via the test code but no luck. I've tested in the UI with users that have the profiles I've specified in the test code and it works as expected. 
Hermes Yan 11Hermes Yan 11
From your code you should be requerying the event between lines 12-13 before you assert it is false.
Then again requery the event before line 22 before outputing IsGroupEvent and asserting the joint_meeting__c flag is set.