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
A Raj 9A Raj 9 

list index out of bounds: 0 error in test class for a button

Hi All, Below is the test class for a clone button. getting error on runing class as "List index Out of Bounds: 0 at both the line "obj01.CloneOER();"

Below is the test class code
=============================

@isTest
public class CloneOrderWithLines_Test {

    @testSetup
    static void setupTestData(){
        
        test.startTest();

        account account_Obj = new account(name='Testing Acc', Oracle_Customer_Number__c='Test Oracle');
        Insert account_Obj;
        system.debug('=============value of account_Obj================'+account_Obj);        

        opportunity opportunity_Obj = new opportunity(Name='Testing Opp', StageName='Closed - Does Not Qualify',
                                      Support_Region__c='New York', Target_SE__c='0054C000000XzsW', CloseDate=date.today(),
                                      Project_State__c='NY', Construction_Type__c='New Construction',
                                      Project_Name__c='Testing Proj', Project_Country__c='United States',
                                      Project_Building_Size__c='10K - 20K', Approx_glass_quantity__c=5,
                                      Project_Stage__c='Land Acquisition,Bid Awarded', Market_Segment__c='Education',
                                      Project_Glass_Installation_Timing__c='3 - 6 Months', LeadSource='Database');
        Insert opportunity_Obj;
        system.debug('=============value of account_Obj================'+opportunity_Obj);
        
        Order_Entry_Release__c Order_Entry_Release_Obj = new Order_Entry_Release__c(Release_Name__c = 'Testing Release',
                               Shipping_Account__c = account_Obj.id, Billing_Account__c = account_Obj.id,
                               Sold_to_Account__c= account_Obj.id, Opportunity__c=opportunity_Obj.id);

        system.debug('=============value of Shipping_Account__c================'+ Order_Entry_Release_Obj.Shipping_Account__c);
        system.debug('=============value of Billing_Account__c================'+ Order_Entry_Release_Obj.Billing_Account__c);

        Insert Order_Entry_Release_Obj;
        system.debug('=============value of Order_entry_release_Obj================'+ Order_Entry_Release_Obj);
        
        Order_Entry_Line__c Order_Entry_Line_Obj = new Order_Entry_Line__c(Order_Entry_Release__c = Order_Entry_Release_Obj.id,
                            Quantity__c = 1, Base_in__c = '15', Height_in__c = '20');
        Insert Order_Entry_Line_Obj;
        system.debug('=============value of Order_entry_line_Obj================'+ Order_Entry_Line_Obj);

        test.stopTest();
    }

    static testMethod void test_CloneOER_UseCase1(){
        
        List<Order_Entry_Release__c> Order_Entry_Release_Obj  =  [SELECT Id, Name, Release_Name__c, Shipping_Account__c,
                                     Billing_Account__c, Sold_to_Account__c from Order_Entry_Release__c];
        System.assertEquals(true, Order_Entry_Release_Obj.size()>0);
        
        List<Order_Entry_Line__c> Order_Entry_Line_Obj  =  [SELECT Id, Name, Order_Entry_Release__c, Quantity__c,
                                                            Base_in__c, Height_in__c from Order_Entry_Line__c];
        System.assertEquals(true, Order_Entry_Line_Obj.size()>0);

        CloneOrderWithLines obj01 = new CloneOrderWithLines(new ApexPages.StandardController(Order_Entry_Release_Obj[0]));
        
        system.debug('=============value of obj01================'+ obj01.newOER);

        obj01.oldOER = new Order_Entry_Release__c();
        obj01.newOER = new Order_Entry_Release__c();
        
        obj01.oerNumStr = '123';
        obj01.oerNum = 123;
        obj01.oerMap = new Map<Id, Order_Entry_Release__c>();
        obj01.maxOERNumber = 1;
        
        system.debug('=============value of obj01================'+ obj01);
        
        obj01.CloneOER();

    }
    

    static testMethod void test_CloneOER_UseCase2(){
    
        List<Order_Entry_Release__c> Order_Entry_Release_c_Obj  =  [SELECT Id, Name, Release_Name__c, Shipping_Account__c,
                                     Billing_Account__c, Sold_to_Account__c from Order_Entry_Release__c];
        System.assertEquals(true, Order_Entry_Release_c_Obj.size()>0);
    
        List<Order_Entry_Line__c> Order_Entry_Line_c_Obj  =  [SELECT Id, Name, Order_Entry_Release__c, Quantity__c,
                                                             Base_in__c, Height_in__c from Order_Entry_Line__c];
        System.assertEquals(true, Order_Entry_Line_c_Obj.size()>0);

        CloneOrderWithLines obj01 = new CloneOrderWithLines(new ApexPages.StandardController(Order_Entry_Release_c_Obj[0]));
    
        obj01.oldOER = new Order_Entry_Release__c();
        obj01.newOER = new Order_Entry_Release__c();

        obj01.oerNumStr = '123';
        obj01.oerNum = 123;
        obj01.oerMap = new Map<Id, Order_Entry_Release__c>();
        obj01.maxOERNumber = 1;

        Order_Entry_Release_c_Obj[0].Name='ReTesting';
        system.debug('=============value of Order_Entry_Release_c_Obj[0]================'+ Order_Entry_Release_c_Obj[0]);
        Update Order_Entry_Release_c_Obj[0];

        Order_Entry_Line_c_Obj[0].Base_in__c ='16';
        Order_Entry_Line_c_Obj[0].Height_in__c ='21';
        Order_Entry_Line_c_Obj[0].Quantity__c=1;

        Update Order_Entry_Line_c_Obj[0];
        system.debug('=============value of Order_Entry_Line_c_Obj[0]================'+ Order_Entry_Line_c_Obj[0]);
   
        obj01.CloneOER();
  }

}

=============================

 
Raj VakatiRaj Vakati
Can u share the CloneOER method logic here .. that is causing an issue 
A Raj 9A Raj 9
I got it corrected now. Thank You.