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
BigMagBigMag 

Verify Challenge error???

The initial Apex challenge:

public class StringArrayTest {
    private static List<String> ReturnedStrings = new List<String>();
    public static void generateStringArray (Integer StringsCount){
        for (Integer i = 0; i < StringsCount;i++){
            ReturnedStrings.add('Test ' + String.valueOf(i) );
            System.debug(ReturnedStrings);
        } 
    }
}
ran nicely in the devlopper console.
User-added image
But I got this error when I clicked Check 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.
 
Best Answer chosen by BigMag
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I  hope that will help you.

 
public class StringArrayTest
{
    public static List<String> generateStringArray(Integer n)
    {
        List<String> List1 = new List<String>();
        for(Integer i =0; i < n; ++i)
            List1.add('Test ' + i);
        return List1;
    }
}



You've correctly constructed the strings for each iterations, but your method is declared as void, meaning nothing will be returned. You will need to refactor your method to meet the requirements above, and then it will pass the assessment. Good luck!
https://developer.salesforce.com/forums/?id=906F0000000BKOTIA4

Please let us know if this will help you.

Thanks
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I  hope that will help you.

 
public class StringArrayTest
{
    public static List<String> generateStringArray(Integer n)
    {
        List<String> List1 = new List<String>();
        for(Integer i =0; i < n; ++i)
            List1.add('Test ' + i);
        return List1;
    }
}



You've correctly constructed the strings for each iterations, but your method is declared as void, meaning nothing will be returned. You will need to refactor your method to meet the requirements above, and then it will pass the assessment. Good luck!
https://developer.salesforce.com/forums/?id=906F0000000BKOTIA4

Please let us know if this will help you.

Thanks
Amit Chaudhary
This was selected as the best answer
BigMagBigMag
Thanks Amit!!!