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
Unnamalai SubramanianUnnamalai Subramanian 

What's wrong in Trailhead Apex class exercise 1?

Hi,

I tried writing the sample apex class to return list of strings. Below is the code and when I check the challenge - I get the error as "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.". What's wrong in the code?

public class StringArrayTest {
    public static List<String> generateStringArray(Integer len) {
 
        Integer inp = len;        
        List <String> Arrlist = new List<String>();
        for(Integer i=0; i < len; i++){
            Arrlist.add('Test: ' + i);
            system.debug(Arrlist.get(i));
          //  system.debug('len value: '  + inp);
        } 
        return Arrlist;
        
    }

}
Best Answer chosen by Unnamalai Subramanian
BalajiRanganathanBalajiRanganathan
Probably yo dont need the colon (:) in your arraylist

you should have this.
 Arrlist.add('Test ' + i);
 

All Answers

BalajiRanganathanBalajiRanganathan
Probably yo dont need the colon (:) in your arraylist

you should have this.
 Arrlist.add('Test ' + i);
 
This was selected as the best answer
Unnamalai SubramanianUnnamalai Subramanian
Yes, That was it! Removing colon worked, Thank you for instant response!