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
newbiewithapexnewbiewithapex 

How to write test class for method that add Invitees?

This is the only method I have in this class and I am trying to figure out how to write test class for SQL queries and what is @AuraEnabled? Any help and explaination would help me a lot.

public with sharing class CBR_AddInviteesCntrl {
    
    @AuraEnabled
    public static Event getCBREventDetails(String cbrId){
        Event eve = [SELECT Id, Type, IsAllDayEvent, Location,  OwnerId,  ActivityDate, Description, DurationInMinutes, RecordTypeId, RecordType.Name,
                                     EndDateTime,  EventSubtype, WhoId, isRecurrence, IsPrivate, WhatId, ShowAs, StartDateTime, SC_Responsible__c, ROC_Primary_Deployment__c,
                                     RecurrenceType ,RecurrenceInterval ,RecurrenceMonthOfYear,RecurrenceInstance,RecurrenceDayOfWeekMask ,RecurrenceDayOfMonth,
                                     FFC_Deployment_Type__c, ROC_Comments_for_Other_Deployment__c, Reminder_Duration_LEX__c, Additional_Attendee_Type__c, Follow_Up_Required__c,
                                     RecurrenceActivityId , Subject, Frequency_Details__c, RecurrenceEndDateOnly FROM Event where CBR__c=:cbrId LIMIT 1];
        return eve;
    }

}
Martha VMartha V
Your test class has to create a couple of records in the Event object, as well as the records related like the WhoId or WhatId. Once you populate the objects needed then you call the method getCBREventDetails with the parameters needed saving the returned record in an event variable.
You can then use the system.assert method to make sure you are getting the expedted result (the record you want). Since this method doesn't have any IF statements it would be fairly easy to test, test it by sending the Id of the record you inserted and then by sending an id of a record that doesn't exist to test for not found.  The @AuraEnabled tag doesn't change the way you test apex classes.

I hope this was clear enough.