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
Jennifer T VegaJennifer T Vega 

Get Started with APEX Error

Hi - I'm not sure why I'm getting the following error when I try to submit my challenge: 

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.

Below is my code:
public class StringArrayTest {

//public static method called 'generateStringArray'
//return an array (list) of strings.
//each string must have a value in this format: 'Test n' (n=index of the current string in the array)
//The number of returned strings is specified by the integer parameter to the 'generateStringArray'method

    public static list<String> generateStringArray(Integer parameter){
        
        
        
        List<String> listofStrings = new List<String>();
        //listofStrings.add('Test n'); Adding this before the loop didn't give me values for n
        //List<String> listofStrings = new List<String>{'Test n'}; Same issue as above. Defined too early. 
       
     
     
        for(Integer n=0; n<= parameter; n++){
           listofStrings.add('Test '+n);
            
            
           //System.debug('n:'+n); This helped me to find out that I am getting the numbers for n that I want. 
            
            //System.debug('listofStrings: '+listofStrings); This was too early and inside the loop, so I was
            //getting a line in the system debug each time the loop ran. 
            
        }
      System.debug('listOfStrings:' +listofStrings);
               
        return listofStrings;
        
    }
    
    
}

And this is what I've put in Execute Anonymous:
List<String>listofStrings = StringArrayTest.generateStringArray(5);
Best Answer chosen by Jennifer T Vega
Amit Chaudhary 8Amit Chaudhary 8
Please check below post same issue
1) https://developer.salesforce.com/forums/?id=906F0000000MJbnIAG
2) https://developer.salesforce.com/forums/?id=9060G000000I2bhQAC
 
public class StringArrayTest {
        public static String[] generateStringArray(Integer length) {
        String[] myArray = new List<String>();
        for(Integer i=0;i<length;i++) {
           myArray.add('Test ' + i);

            System.debug(myArray[i]);
        } 
        return myArray;
    }     
}

NOTE:- try loop from i=0 to i < length

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);

Let us know if this will help you
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please check below post same issue
1) https://developer.salesforce.com/forums/?id=906F0000000MJbnIAG
2) https://developer.salesforce.com/forums/?id=9060G000000I2bhQAC
 
public class StringArrayTest {
        public static String[] generateStringArray(Integer length) {
        String[] myArray = new List<String>();
        for(Integer i=0;i<length;i++) {
           myArray.add('Test ' + i);

            System.debug(myArray[i]);
        } 
        return myArray;
    }     
}

NOTE:- try loop from i=0 to i < length

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);

Let us know if this will help you
 
This was selected as the best answer
Jennifer T VegaJennifer T Vega
Thank you so much! All I needed to do was to remove the "="!!! Ahhh.