Would like to seek for assistance, already debug my code but still error :(
@isTest static void fetch() {
system.runAs(new User(Id = UserInfo.getUserId())){
Account testAcc = new Account();
testAcc.Name = 'Sample';
testAcc.Bill_To_Code__c = '0080101010';
testAcc.Branch_Code__c = '0080101010';
testAcc.Branch_Name__c = 'Sample';
insert testAcc;
Event testEvent = new Event();
testEvent.Subject = 'Test';
testEvent.ActivityDate= date.today();
testEvent.StartDateTime = date.today();
testEvent.EndDateTime = dateTime.now();
testEvent.Event_Type__c = 'Call';
testEvent.Event_Sub_type__c = 'BRANCH CALL';
testEvent.Location_Based__c = 'Home Base';
testEvent.Related_to_Account__c = testAcc.Id;
testEvent.Work_Plan__c = false;
testEvent.Status__c = 'New';
insert testEvent;
Test.startTest();
Id acct = GTA.fetch(testAcc.Id);
Test.stopTest();
} }
Here's my class
public class GTA { @AuraEnabled public static string fetch(string recordID){ List<Event> oEvent = [SELECT Related_To_Account__c FROM Event WHERE Id=:recordID]; return oEvent[0].Related_To_Account__c; } }
Error: System.ListException: List index out of bounds: 0
Trace: Class.GTA.fetch: line 8, column 1