+ Start a Discussion
PeacePeace 

Calling global variables into webservice method

Hi,

I am new to apex, please help me implementing following simple scenario:

I have a picklist on VisualForce page and a command button.

 Select Object <apex:selectList required="true" multiselect="false" size="1" label="Type"  value="{!selectedValue}">
    
  <apex:selectOptions value="{!Items}"/>
  </apex:selectList>     
<apex:commandButton action="{!ReadContents}" value="Next" id="theButton" /> 

 Controller:

global class FetchRecords {

public static string selectedValue{get;set;}  //contains the object selected from picklist.

   public List<SelectOption> getItems()
    {
    // Code to populate picklist values, comes here
    return options1;
     }


 webservice static List < SObject > ReadContents() {
 
 List < SObject > ObjectContents; 
 
    query += 'select ...';
       ObjectContents = database.query(query);
    
return ObjectContents;
 }
 }

  
 I am getting Compile Error: The property String selectedValue is referenced by Visualforce Page (FetchRecords) in salesforce.com. Remove the usage and try again
 
 Please help to resolve above error.

 

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Comment out the visualforce code then save the class. It will save properly and then again open the visualforce code.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks