You need to sign in to do that
Don't have an account?
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}"/> </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(); } }
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; }
All Answers
Why would you use outputField in this case. Why not simply use:
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'
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; }
Hi Jill,
Thank you very much for your explanation.