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
hisrinuhisrinu 

How to access member variables of class in webservice method?

Hi,

 

 I want to use the class member variable in the webservice method.

 

global class test123 { List<Opportunity> selopplist1 = new List<Opportunity>(); WebService static void getFromListPage(String[] IdList) { SelOppList1 = [select Name, Account.Name, Type from opportunity where id in :IdList]; } }

 Here I want to use selopplist1 in the webservice method, but I am getting an error like variable is not declared.

I tried by keeping global as well as webservice keyword before the declaration but still I am getting the same error.

Any help on this highly appreciated

 

 

SuperfellSuperfell
the webservice method is static, so you first need to create an instance of the class before you can access any class level variables.
hisrinuhisrinu

Thanks Simon,

 

 One more question, 

 

   I have a list button, on click of it I am sending the selected records IDs to the apex class by using the s-control.

   In that apex class I am getting these rows, I want to display these records in that VF, how can I redirect it to the visualforce page. When I am redirecting using s-control view state is getting refreshed. So I am not getting any records, If I am trying to return through webservice method it is showing an error like  Invalid return type: System.PageReference

 

Any help on this.

 

rawiswarrawiswar
hmm ... static cannot access non-static ... any pointers to where i can read about inner, outer class access methodology and restrictions?(pretty sure i read something somewhere)