function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fiona gentryfiona gentry 

Why getting Static method cannot be referenced from a non static context: List<String> From Execute Anonymous Code

Hi,

Below is apex code which i am terying to execue in "Open Execute Anonymous Window"
SDSAfterConvert n1 = new SDSAfterConvert();
n1.returnInteger();


Here is Apex class
public class SDSAfterConvert {
    
    
public static List<String> returnInteger(){

List<String> inputList = new List<String>();
             
String[] myAlphabets = new String[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'g'};
 
for (String s1 : myAlphabets) {
    System.debug(s1);
    inputList.add(s1);
}
        
return inputList;
             
}
    
}


Can anyone help why i am getting this error as My method is static and arrays can be returned from static

Regards,
Fiona



 
Best Answer chosen by fiona gentry
Shatrughna SalunkeShatrughna Salunke
1. We can't call the static method from a non-static context.
2. Please use the below code to call a static method from Execute Anonymous Window
 
 SDSAfterConvert.returnInteger();


Tks,
Shatrughna