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
Brock ShagenaBrock Shagena 

Hello, Started working on the " getting started with Apex" trail. I wrote the code based on my understanding of the requirements .Not sure what I am missing it seems to work when I run it in the dev console. See code below. Thanks

public class StringArrayTest {
    public static List<String> generateStringArray(){
        Integer iteration = 5;
        List<String> testList = new List<String>{};
            for(Integer i =0; i < iteration; i++){
                testList.add('Test'+ ' ' + i);
                system.debug(testList.get(i));}
  
        Return testList;
    }
}
Brock ShagenaBrock Shagena
Also... here is the error message  Challenge Not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.
Brock ShagenaBrock Shagena
Ok got it... appended the code (I had done this before and did not seem to work) to include an integer parameter in the method signature
public class StringArrayTest {
    public static List<String> generateStringArray(Integer iteration){
        
        List<String> testList = new List<String>{};
            for(Integer i =0; i < iteration; i++){
                testList.add('Test'+ ' ' + i);
                system.debug(testList.get(i));}
  
        Return testList;
    }
}

   
Amit Chaudhary 8Amit Chaudhary 8
Please update your code like below
public class StringArrayTest {
    
    public static List<String> generateStringArray(Integer iteration)
    {
        List<String> myArray = new List<String>();
        for(Integer i=0;i<iteration;i++)
        {
           myArray.add('Test '+i);
           System.debug(myArray[i]);
        }
        return myArray;
    }
}
And go :
Your Name>Developer Console>Debug>Open Execute Anonymous Window 
Paste below code in it
list<string> myArray = StringArrayTest.generateStringArray(10);
system.debug('************'+myArray);
Check below post for more info
https://developer.salesforce.com/forums/?id=9060G000000I2bhQAC

Let us know if this will help you