You need to sign in to do that
Don't have an account?
ux5
Trailhead Challange not yet complete- (Getting started with APEX module)
On the getting started with APEX, I cannot complete the challange and I am receiving the following error:
But in the Debug Execute Anonymous Window, I can successfully run the code. Here is the code used in the Anonymous window.
List<String> rtnStr = StringArrayTest.generateStringArray(4);
System.debug(rtnStr);
System.debug('rtnstr.size='+rtnstr.size());
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.
But in the Debug Execute Anonymous Window, I can successfully run the code. Here is the code used in the Anonymous window.
List<String> rtnStr = StringArrayTest.generateStringArray(4);
System.debug(rtnStr);
System.debug('rtnstr.size='+rtnstr.size());
As prevously said, if I do a Check Challange from the trailhead module I recieve the error. In looking at the log there are two suspicious lines.
18:53:07:031 EXCEPTION_THROWN [1]|System.AssertException: Assertion Failed: Expected: Test 1, Actual: Test 0
18:53:07:031 FATAL_ERROR System.AssertException: Assertion Failed: Expected: Test 1, Actual: Test 0
18:53:07:031 FATAL_ERROR System.AssertException: Assertion Failed: Expected: Test 1, Actual: Test 0
Can anyone help with this. Adding a test case did not remedy the problem but I may have done something wrong there.
And here is my code:
public class StringArrayTest {
public static String[] generateStringArray(Integer count){
List<String> mylist = new List<String>();
for (Integer i=1; i<=count; i++) {
String myStr = 'Test ' + i;
System.Debug('Created '+ myStr);
mylist.add(myStr);
}
System.debug('Completed!');
return mylist;
}
}
Question is: Should I have to have a test case to complete this challange or have I got something else wrong?
TIA for your help
ux5
And here is my code:
public class StringArrayTest {
public static String[] generateStringArray(Integer count){
List<String> mylist = new List<String>();
for (Integer i=1; i<=count; i++) {
String myStr = 'Test ' + i;
System.Debug('Created '+ myStr);
mylist.add(myStr);
}
System.debug('Completed!');
return mylist;
}
}
Question is: Should I have to have a test case to complete this challange or have I got something else wrong?
TIA for your help
ux5
Please check below post. I hope that will help u.
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AvPBIA0
Please try below code:- I hope you need to start loop from 0 to <n
Please let us know if this will help u
Thanks
Amit Chaudhary
thx.
Hi ux5,
Below is the code I used to complete my trailhead challenge:
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;
}
}
This is what worked for me. Enjoy!
public class StringArrayTest {
public static List<String> generateStringArray(Integer n)
{
List <String> ListFields = new list<String>();
String s;
integer x;
for(x=0;x<n;x++){
s='Test ' + x;
ListFields.add(s);
}
return(ListFields);
}
}