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
Allen MoyAllen Moy 

Challenge with SOQl to VisualForce Page

I used the example on this site as a model to build my custom controller and page but my resulting page has no data. What am I missing?

Here is my custom controller:
public with sharing class MarketReservationDetails {
 
    public List <Farmers_Market_Reservation__c> Records {get; set;}
    public MarketReservationDetails() {
        Records = 
            [SELECT id, Farmers_Market_Day__c, Producer_Type__c, Producer_Name__c, 
               Producer_Stall_Space__c FROM Farmers_Market_Reservation__c
               WHERE RecordTypeID='01216000001IiQx'
               AND Farmers_Market_Day__c=:ApexPages.currentPage().getParameters().get('id')];
    }
}

And here is my page:

<apex:page controller="MarketReservationDetails" sidebar="false" showHeader="false">
    <apex:form >
    <apex:pageBlock >
    <apex:pageMessages />
    <apex:pageBlock >
        Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first. 
    </apex:pageBlock>
    <apex:pageBlockTable value="{!Records}" var="R">
        <apex:outputField value="{!R.Producer_Type__c}"/>
            <apex:outputField value="{!R.Producer_Name__c}"/>
            <apex:outputField value="{!R.Producer_Stall_Space__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>    
</apex:page>    
Mahesh DMahesh D
Hi Allen,

Could you please check whether you are have corresponding data in your environment, if yes then first try to remove the filter conditions and check the results. If you get the results without filters then look for the right filters.

Regards,
Mahesh
sumit singh 37sumit singh 37
please add  Farmers_Market_Day__c id in the url as  e.g     ?id='906F0000000D9AyIAK'        
rajesh sharma 22rajesh sharma 22
hi Allen,

first of all if there is error in your query. you hav to use colon ':' before id.like following:- 
Account=   [SELECT id,name FROM Account where id=:'0012800000IbWgx'];   delete the AND statement from the query;

second if you want to fetch a single record you don't have need to use List...

 
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri
@rajesh sharma - we shouldn't use colon when we are matching with value directly
Amit Chaudhary 8Amit Chaudhary 8
Hi Allen,

I found below issue in your query
1) Never use the hardcord ID in query. Try to modify like below
[SELECT id, Farmers_Market_Day__c, Producer_Type__c, Producer_Name__c, 
               Producer_Stall_Space__c FROM Farmers_Market_Reservation__c
               WHERE RecordType.Name='add Record Type Name here'
               AND Farmers_Market_Day__c=:ApexPages.currentPage().getParameters().get('id')];
2) I hope you are passing valid Record ID of Farmers_Market_Day__c in URL ?

Please let us know if this will help you
 
Allen MoyAllen Moy
Thanks to everyone for your input. I was able to correct my controller and my VF Page and everything is working!