Reputation: 139
I am trying to learn Apex after spending a lot of time on Java and C++ in school. In a previous life I was a heavy user of SFDC and helped chose it for our org at the time. So Apex seems like a natural progression.
In that process I am trying to complete these "trailhead challenges". The first one is Create an Apex class that returns an array (or list) of strings:
Code in the SFDC Developer console...
public class StringArrayTest
{
public static String [] generateStringArray(integer size)
{
String [] locStrArray = new String [size];
//set values in array...
for (integer i = 0; i < size; i++)
{
locStrArray[i] = 'Test ' + i;
}
//display array...
for (integer i = 0; i < size; i++)
{
System.debug(locStrArray[i]); //when in doubt, system out...
}
return locStrArray;
}
}
Code In the Open Execute Anonymous Window...
integer size =10;
String [] strArray = new String [size];
strArray = StringArrayTest.generateStringArray(size);
for (integer i = 0; i < size; i++)
{
strArray[i] = 'Test ' + i;
system.debug('B ' + strArray[i]); //when in doubt, system out...
}
Here is what appears to be the access violation I am getting...
Line: 3, Column: 28
Method is not visible: void StringArrayTest.generateStringArray(Integer)
This thing works in Netbeans with system.debug()
being replaced by system.out.println()
This challenge might not even be valid anymore as I started it last spring then put it down til now. Mostly I am just trying to understand the behavior of their online IDE relative to the quirks other IDEs have. This seems like a pretty simple program that should be pretty straight forward. Is there a background rule at work?
Upvotes: 0
Views: 5470
Reputation: 24
public class StringArrayTest {
public static List<String> generateStringArray(Integer n){
List<String> strings = new List<String>();
integer count = 0;
While(count < n){
strings.add('Test ' + count);
count ++;
}
System.debug(strings);
return strings;
}
}
Upvotes: -1
Reputation: 7371
Do you have custom namespace for your class? I assume, that code from Anonymous Window may be compiled in some inner SF class without namespace and in such case your public classes (under your custom namespace) will be not available from there. If it's so, try to change 'public' to 'global' for your class.
Upvotes: 0