0

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
4
  • 2
    Looks like the bug is on your GTA class, not inside your test. Sep 30, 2020 at 13:36
  • 1
    When asking for help with an error, it's important to include the error message in its entirety (including the stack trace), word for work. Paraphrashing or leaving parts of the error message out make it somewhere between hard and impossible for people to figure out what the issue is.
    – Derek F
    Sep 30, 2020 at 13:54
  • @MartinLezer my class already posted
    – Akosi Jeff
    Oct 1, 2020 at 0:05
  • @DerekF my apologize for lack of information. Posted already.
    – Akosi Jeff
    Oct 1, 2020 at 0:05

1 Answer 1

1

Already solved, I figure out that my Id on the start test should be Event not Account

From:
Id acct = GTA.fetch(testAcc.Id);

To:
Id acct = GTA.fetch(testEvent.Id);

Not the answer you're looking for? Browse other questions tagged .