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
Dilip_VDilip_V 

Unknown property Error in VF

I wrote a page for Searching.I declared a list in controller InvByLocation.

But when I am trying to Access the list it was showing Error: Unknown property 'InvLocationSearchContr.InvByLocation.
 
public with sharing class InvLocationSearchContr 
{

  
    public Boolean refer { get; set; }
    public string location { get;set;}
    public List<Inventory__C> InvByLocation=new List<Inventory__C>();
    public PageReference Search()
    {
         refer=true;
         InvByLocation=[Select Name,Location__C From Inventory__C where Location__C='Location'];
         return null;
    }



}


<apex:page Controller="InvLocationSearchContr" showHeader="False">
  <apex:form id="MyF">
  <apex:pageBlock title="Inventory Search By Location">
  <apex:pageBlockSection >
      <apex:inputText value="{!Location}" label="Location"/>  
  </apex:pageBlockSection>
  <apex:pageBlockSection >
      <apex:commandButton action="{!Search}" value="Search" style="background:black;font-weight:bold;color:white"/>
  </apex:pageBlockSection>
  </apex:pageBlock>
  <apex:pageblock rendered="{!refer}">
      <apex:pageBlockTable value="{!InvByLocation}" var="lap">
          <apex:column value="{!lap.Name}"/>
          <apex:column value="{!lap.Location__c}"/>
      </apex:pageBlockTable>
  </apex:pageblock>
  
  
  
  </apex:form>
</apex:page>

 
Best Answer chosen by Dilip_V
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
public with sharing class InvLocationSearchContr 
{

  
    public Boolean refer { get; set; }
    public string location { get;set;}
    public List<Inventory__C> InvByLocation {get;set;}
	
	public InvLocationSearchContr()
	{	
		InvByLocation = new List<Inventory__C>();
	}
	
    public PageReference Search()
    {
         refer=true;
         InvByLocation=[Select Name,Location__C From Inventory__C where Location__C='Location'];
         return null;
    }



}

 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
public with sharing class InvLocationSearchContr 
{

  
    public Boolean refer { get; set; }
    public string location { get;set;}
    public List<Inventory__C> InvByLocation {get;set;}
	
	public InvLocationSearchContr()
	{	
		InvByLocation = new List<Inventory__C>();
	}
	
    public PageReference Search()
    {
         refer=true;
         InvByLocation=[Select Name,Location__C From Inventory__C where Location__C='Location'];
         return null;
    }



}

 
This was selected as the best answer
SonamSonam (Salesforce Developers) 
InvByLocation must be declared as a property of the controller as a getter and setter.
Dilip_VDilip_V
Thank you for quick response.Problem Solved.

May I know the reason behind it.

Thanks.