You need to sign in to do that
Don't have an account?
Collaborative e
Visualforce Error "Unknown Property 'String.File_Name__c'"
Built a controller and an visualforce page. Trying to gather records from an object and then use <apex:repeat> to display them on the page. Here's the controller code:
public class MyCustomRentalExtension { //The standard controller on which this extension is based Custom_Rental__c rental; //Properties of this class public String booth {get;set;} List<Custom_Rental__c> allSizes = new List<Custom_Rental__c>(); //Constructor public MyCustomRentalExtension() { //set the default size booth = '10x10'; //on page load, get the size param from the URL String sizeParam = ApexPages.currentPage().getParameters().get('booth'); if (sizeParam != ''){ for (Custom_Rental__c cr : allSizes){ if(cr.Booth__c == sizeParam){ booth = cr.Booth__c; } } } } //List records for a specific booth size public List<Custom_Rental__c> getBooths() { return [Select p.id, p.File_Name__c, p.Preview_Link__c from Custom_Rental__c p where p.Booth__c = :booth Order By p.File_Name__c]; } }
Here is the VF Page:
<apex:page showHeader="false" id="body" standardStylesheets="false" controller="MyCustomRentalExtension" cache="true" expires="600"> <head> <title>{!booth} Customer Rental Extension Site</title></head> <h2> {!booth} Custom Rental Portfolio</h2><br/> <p>To learn more about our {!booth} custom rental solutions click on one of the booth photographs below.</p><br/> <apex:form id="form"> <apex:outputPanel id="list"> <apex:repeat value="{!Booths}" var="booth" id="boothList"> <div style="float: left; padding:0; margin:0px 15px 15px 0px;"> <h4 align="center">{!booth.File_Name__c}</h4> <div style="border: 2px solid #e2e2e2; margin:0; padding:2px;"> <a href="Page1?id={booth.id}"> <img src="{!booth.Preview_Link__c}" width="250" height="200" alt="{!booth.Name}" /> </a> </div> </div> </apex:repeat> </apex:outputPanel> </apex:form> </apex:page>
I am getting an error on the VF page saying "Unknown Property 'String.File_Name__c'
Try changing the variable name from booth to, maybe, b...
so instead of
<apex:repeat value="{!Booths}" var="booth" id="boothList">
try
<apex:repeat value="{!Booths}" var="b" id="boothList">
I have a feeling that {!booth.File_Name__c} is making a call to your getter method on the booth variable.
All Answers
Try changing the variable name from booth to, maybe, b...
so instead of
<apex:repeat value="{!Booths}" var="booth" id="boothList">
try
<apex:repeat value="{!Booths}" var="b" id="boothList">
I have a feeling that {!booth.File_Name__c} is making a call to your getter method on the booth variable.
Thanks knthornt1. That fixed that problem. I have updated the code here:
Controller
VF Page
One more issue: when I enter the URL with ?Booth=10x10 it changes the value of {!sqft} but does not dynamically fill in the information from the list I created in the controller.
It creates a thumbnail box for each record found but offers no title, link, etc.
You can see this here: https://freemanco.freemanuat.cs12.force.com/customrentals/page1?Booth=Island
Not sure if this will help, but try changing
Select p.id, p.File_Name__c, p.Preview_Link__c from AWS_S3_Object__c p where p.Booth__c = :sqft Order By p.File_Name__c
to
Select id, File_Name__c, Preview_Link__c from AWS_S3_Object__c where Booth__c = :sqft Order By File_Name__c
Also, for the preview link, might URLFOR() help there? give that a shot and see if that helps at all. You might need some other help beyond what I can provide here though.
Thanks for the continued thoughts and help knthornt1.
Tried changing the select statement as you mentioned. Got an error:
"No such column 'File_Name__c' on entity 'Custom_Rental__c'.
My apologies. Constroller is as listed below. Trying to call SELECT statement from Custom_Rental__c object. Not from AWS_S3_Object__c.
Controller
And VF Page:
The error would indicated that you don't have the field File_Name__c on that object. you had AWS_S3_Object__c in there before and it was working, is File_Name__c the proper API name for that field on the Custom Rental object?
Sorry for the confusion. Yes File_Name__c is the proper API name for the field in the Custom Rental Object.
Hi Kyle and Kevin!
Kevin, can you try the following: take that direct query out of that method, and place it in the constructor and set it to a List<Custom_Rental__c> with get; set;
i.e. public List<Custom_Rental__c> booths {get; set;}
and constructor
public MyCustomRentalExtension() {
booths = [Select p.id, p.File_Name__c, p.Preview_Link__c from Custom_Rental__c p where p.Booth__c = :sqft Order By p.File_Name__c]
}
There maybe something goofy with the order of operations
Thanks Shoby. I'm confused...would it then look like this?
Thats correct. It simply maybe an issue with order of operations.
No change in the situation. Still seeing blank values on visualforce page:
http://freemanco.freemanuat.cs12.force.com/customrentals?booth=10x10
To ensure we're on the same page. Here's what the Class looks like now:
Here's the VF Page:
If there is a better/simplier way to do this I'm all ears...
The sqft value is showing up on the page from the looks of it, just not the data. I have to ask on whether the Sites profile has access to those custom objects and fields
Fair question Shoby. I had given the Site Profile (in this case it was the "Custom Rental" profile) access to the "Custom_Rental__c" object with read rights to the object and all fields.
I had NOT given access for the profile to be able to run the MyCustomRentalExtension class :smileymad:
Closer...but now I get the Authorization Required sites page when I try to go to the site link I provided above.
The site profile has read access to the one object I'm using and to the class. What else could I be missing?
More strangeness.
When I change the "Custom_Rental__c" object to "Deployed" I get the "Authorization Required" error. When I change it back to "In Development" I see the 4 empty image boxes.
I feel stupid for asking this...but does it make a difference that this is in a full sandbox?