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
RuleyRuley 

Unknown Property Error using Custom Controller

I have an error with a new Visualforce page I'm creating that takes advantage of a custom controller I made. It is all around custom objects I build, and the class file compiled just fine. But when I start building the Visualforce page it gives me an error that I can't for the life of me figure out.

 

This is the Visual Force Page

 

 

<apex:page controller="TaskTimeEntryController" showHeader="true" sidebar="false">
	<apex:form id="TimeEntryForm">
		<apex:pageBlock >
			<apex:pageBlockSection >
				{!$User.FirstName} {!$User.LastName}
			</apex:pageBlockSection>
			<apex:pageBlockSection >
				<apex:pageBlockTable value="{!lstTasksForUser}" var="lstTasks" width="100%">
					<apex:column HeaderValue="Select">
						<apex:outputText Value="{!lstTasks.Name}"></apex:outputText>
					</apex:column>
				</apex:pageBlockTable>
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

 

And the Controller:

 

public class TaskTimeEntryController {
	public List<Task__c> lstTasksForUser = new List<Task__c>();
	public List<Time_Entry__c> lstTimeToEnter = new List<Time_Entry__c>();
	
	public TaskTimeEntryController(){
		populateTaskList();
	}
	
	private void populateTaskList() {
		lstTasksForUser = [
			Select Name, Task_Status__c, Current_Hours__c, Current_End_Date__c, Current_Duration__c, Assigned_To__c, 
				(Select Estimated_Time__c From Future_Time_Entries__r)
			From Task__c 
			WHERE Assigned_To__c = :UserInfo.getUserId()];
	}
	
	public List<Task__c> getUsersTasks() {
		return lstTasksForUser;
	}
}

 

 

The class compiles fine, I'm using the Force.com IDE, so that seems to be okay. But then when I go to save my Visualforce page it gives the following error:

 

Save error: Unknown property 'TaskTimeEntryController.lstTasksForUser'

 

I've looked over a the variable names a bunch of times and even copied another sample that was the same structure and it compiles just fine, but when I change to my objects, error. I'm sure I'm missing something simple.

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

Your getter is called getUserTasks() so you need {!userTasks}.  The format you're using is for use with the property syntax, e.g. 

	public List<Task__c> lstTasksForUser {get;set;}

You can move your getter into this definition and then refer to it as "{!lstTasksForUser}" if you want.

All Answers

jwetzlerjwetzler

Your getter is called getUserTasks() so you need {!userTasks}.  The format you're using is for use with the property syntax, e.g. 

	public List<Task__c> lstTasksForUser {get;set;}

You can move your getter into this definition and then refer to it as "{!lstTasksForUser}" if you want.

This was selected as the best answer
RuleyRuley

I should have posted this a while ago because that was an easy fix, just swaped out what you have for my second line and everything worked perfectly.

 

Thanks Jill.

Lakshey MendirattaLakshey Mendiratta

Error: Unknown property 'Sample1.WrapperClass.acct'

I am facing this error.
Class is running fine, but vf page is showing error.






Code for vf page is as below:



<apex:page controller="Sample1" tabStyle="Account">
<apex:form >
<apex:pageMessages />
   <apex:pageBlock id="pg">
       <apex:pageBlockSection >
           <apex:pageBlockTable value="{!listWrapper}" var="a">
             
              
               <apex:column value="{!a.acct.name}"/>
               </apex:pageBlockTable>
            
       </apex:pageBlockSection>
           
    
   </apex:pageBlock>
</apex:form>
</apex:page>





code for controller:
public class Sample1 {
 public List < WrapperClass > listWrapper {
  get;
  set;
 }


 public Sample1() {
  queryacc();
 }

 public void queryacc() {
  List < Account > listAcct = [SELECT Name FROM Account LIMIT 1000];
  listAcct.sort();

  if (listAcct.size() > 0) {
   listWrapper = new List < WrapperClass > ();


  }

}


  public class WrapperClass implements Comparable {

   public string acctname {
    get;
    set;
   }

   public WrapperClass(Account acct) {
    this.acctname = acct.Name;
   }
   public Integer compareTo(Object compareTo) {
    WrapperClass compareToEmp = (WrapperClass)compareTo;
        if (acctname == compareToEmp.acctname) return 0;
        if (acctname > compareToEmp.acctname) return 1;
        return -1;
   }



  }
 }