You need to sign in to do that
Don't have an account?
Jennifer 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);
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);
1) https://developer.salesforce.com/forums/?id=906F0000000MJbnIAG
2) https://developer.salesforce.com/forums/?id=9060G000000I2bhQAC
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
Let us know if this will help you
All Answers
1) https://developer.salesforce.com/forums/?id=906F0000000MJbnIAG
2) https://developer.salesforce.com/forums/?id=9060G000000I2bhQAC
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
Let us know if this will help you