You need to sign in to do that
Don't have an account?
Arunkumar Pandyan Ramar
Error in Apex Module
Hi,
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings."
My code is as shown below.
public class StringArrayTest {
public static List<String> generateStringArray(Integer n){
List<String> str = new List<String>(n);
for(Integer j=0;j<n ;j++){
str.add('Test '+String.valueOf(j));
}
return str ;
}
}
When I test this on the debug-->open execute anonymous window,
with the following code, it runs successfully.
List<String> ls = StringArrayTest.generateStringArray(10);
for (Integer m=0;m<10;m++){
System.debug(ls[m]);
}
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings."
My code is as shown below.
public class StringArrayTest {
public static List<String> generateStringArray(Integer n){
List<String> str = new List<String>(n);
for(Integer j=0;j<n ;j++){
str.add('Test '+String.valueOf(j));
}
return str ;
}
}
When I test this on the debug-->open execute anonymous window,
with the following code, it runs successfully.
List<String> ls = StringArrayTest.generateStringArray(10);
for (Integer m=0;m<10;m++){
System.debug(ls[m]);
}
List<String> str = new List<String>(n);
Please remove n in list of string:
List<String> str = new List<String>();
please check once and let me know in case any help need.
Thanks
Varaprasad
It worked like a charm. No wonder it was sending back 10 null entries and then the correct 10 values.
Thanks again.
Please check below post for same issue
1)https://developer.salesforce.com/forums/?id=9060G000000I2bhQAC
2) https://developer.salesforce.com/forums/?id=906F0000000AvPBIA0
Please try below code:- And go :
Your Name>Developer Console>Debug>Open Execute Anonymous Window
Paste below code in it The Apex class must be called 'StringArrayTest' and be in the public scope.
--> public class StringArrayTest{
The Apex class must have a public static method called 'generateStringArray'.
-->public static List<String> generateStringArray(Integer n) {
The 'generateStringArray' method must return an array (or list) of strings.
-->public static List<String> generateStringArray(Integer n) {
Each string must have a value in the format 'Test n' where n is the index of the current string in the array.
s= 'Test ' + x;
The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
public static List<String> generateStringArray(Integer n) {
Let us know if this will help you
If it helpsyou please mark it as best answer.
Thanks
Varaprasad