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
newbiewvfdevnewbiewvfdev 

OutputField valu binding error when using StandardSetController for paging on custom object

Hi there,

 

I just created a custom object called 'Job' with no additional custom fields. And I am trying to do paging on all the Job records.

 

When I try to save the following code it's throwing me an error:

 

'Could not resolve the entity from <apex:outputField> value binding '{!jobM.Name}'. outputField can only be used with SObject fields.'

 

Here is my code:

visualforce page code: <apex:page controller="customObjectPagingController" > <apex:pageBlock title="Page #{!pageNumberJob}" > <apex:pageBlockTable id="cMJobs" value="{!Jobs}" var="jobM"> <apex:column headerValue="Job Name"> <apex:outputField value="{!jobM.Name}"/>&nbsp; </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:page> Controller code: public class customObjectPagingController { // instantiate the StandardSetController from a query locator public ApexPages.StandardSetController jobs { get { if(jobs == null) { jobs = new ApexPages.StandardSetController( Database.getQueryLocator([ SELECT Name FROM Job__c])); // sets the number of records in each page set jobs.setPageSize(5); } return jobs; } set; } // indicates whether there are more records after the current page set. public Boolean hasNextJob { get { return jobs.getHasNext(); } set; } // indicates whether there are more records before the current page set. public Boolean hasPreviousJob { get { return jobs.getHasPrevious(); } set; } // returns the page number of the current page set public Integer pageNumberJob { get { return jobs.getPageNumber(); } set; } // returns the first page of records public void firstJob() { jobs.first(); } // returns the last page of records public void lastJob() { jobs.last(); } // returns the previous page of records public void previousJob() { jobs.previous(); } // returns the next page of records public void nextJob() { jobs.next(); } public List<Job__c> getJobs() { return (List<Job__c>) jobs.getRecords(); } }

 

 

Best Answer chosen by Admin (Salesforce Developers) 
newbiewvfdevnewbiewvfdev

Hi there,

 

I figured out what the problem was, but not sure why it's a problem.  All, I did was rename the 'jobs' to 'jobs2' and it worked.  Does anyone know why this is the case?

 

 

public ApexPages.StandardSetController jobs2 { get { if(jobs2 == null) { jobs2 = new ApexPages.StandardSetController( Database.getQueryLocator([ SELECT Name FROM Job__c])); // sets the number of records in each page set jobs2.setPageSize(5); } return jobs2; } set; }

 

Message Edited by newbiewvfdev on 03-10-2010 05:07 AM

All Answers

stephanstephan

Why would you use outputField in this case. Why not simply use:

 

<apex:column headerValue="Job Name" value="{!jobM.Name}" />

 

newbiewvfdevnewbiewvfdev

Hi Stephan,

 

The reason I am using OutputField is to let the UI draw properly when there the field is empty. I did try using column as well. If I use that. It gives me the following error:

 

Unknown property 'ApexPages.StandardSetController.Name' 

newbiewvfdevnewbiewvfdev

Hi there,

 

I figured out what the problem was, but not sure why it's a problem.  All, I did was rename the 'jobs' to 'jobs2' and it worked.  Does anyone know why this is the case?

 

 

public ApexPages.StandardSetController jobs2 { get { if(jobs2 == null) { jobs2 = new ApexPages.StandardSetController( Database.getQueryLocator([ SELECT Name FROM Job__c])); // sets the number of records in each page set jobs2.setPageSize(5); } return jobs2; } set; }

 

Message Edited by newbiewvfdev on 03-10-2010 05:07 AM
This was selected as the best answer
jwetzlerjwetzler
when you specify {!jobs} on your VF page, the first thing it will look for is a property with a public/global getter called jobs.  If we don't find that, we'll look for a public/global method called getJobs().  So in your case, getJobs() returns a list of SObjects, but the property jobs returned a StandardController object, which is not a valid object to use with outputField.  Now that you've renamed your property it's using the proper SObject list.
newbiewvfdevnewbiewvfdev

Hi Jill,

 

Thank you very much for your explanation.