You need to sign in to do that
Don't have an account?
Apex Basics and Database Module along the Beginner Developer Trail: List Challenge
Hi All,
I am working with a fresh DE org with no customizations and I am continually failing the first unit of the Apex Basics and Database Module along the Beginner Developer Trail.
The Challenge is below:
Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.
- The Apex class must be called 'StringArrayTest' and be in the public scope.
- The Apex class must have a public static method called 'generateStringArray'.
- The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
...and this is my failing solution:
...and here is the failure 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."
...All my returning debug values seem to be correct. Please help, if possible.
Thanks!
Mark
I am working with a fresh DE org with no customizations and I am continually failing the first unit of the Apex Basics and Database Module along the Beginner Developer Trail.
The Challenge is below:
Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.
- The Apex class must be called 'StringArrayTest' and be in the public scope.
- The Apex class must have a public static method called 'generateStringArray'.
- The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
...and this is my failing solution:
public class StringArrayTest { public static void generateStringArray (Integer rs){ list<string> stringarray = new list<string>(); for(Integer n=0;n < rs;n++){ stringarray.add('Test ' + n); } string a = stringarray[0]; string b = stringarray[1]; string c = stringarray[2]; string d = stringarray[3]; system.debug(a); system.debug(b); system.debug(c); system.debug(d); integer y = stringarray.size(); system.debug(y); } }
...and here is the failure 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."
...All my returning debug values seem to be correct. Please help, if possible.
Thanks!
Mark
Your method is not returning anything. The return type is void, instead of a List<String> like the last bullet point is asking for. Change the return type and add a return statement around line 9, and you should be good to go.
All Answers
Your method is not returning anything. The return type is void, instead of a List<String> like the last bullet point is asking for. Change the return type and add a return statement around line 9, and you should be good to go.
Generally speaking, when is the void return type used?
Thanks for the help.