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
sryansryan 

Custom Controller Errors

Hello.

 

I'm trying to resolve a problem I'm having in VF with getting a custom controller to work.  I based my Apex code and VisualForce markup on an example that I got out of the VF Salesforce Pages Developer's Guide. I'm new to VF and Apex, so I'll do my best to explain.

 

Objective: Write a custom controller (Apex class, e.g. similarConferences) that returns a list of records for a custom object (e.g. Conference__c) selected by a variable field from the custom object (e.g. {!Conference__c.Type_of_Technology__c}).

 

Expected behavior: View the detail of a record on the Conference Tab and click a custom link associated with the custom object to open a new window (VF Page, e.g. similarConference) that renders a list of records for all Conference records that have the same type of technology (i.e. Type_of_Technology__c = current record).

 

Actual behavior: I get an error "Error: Unknown property 'similarConferences.Conference__c'" and two Quick Fixes 1) Create Apex property 'similarConferences.Conference__c' and 2) Create Apexmethod 'similarConferences.getConference__c' when I try testing my VF Page named "similarConference."

 

 

Custom Controller code:

 

public class similarConferences {
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
              setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select
 Name, Conference_Date__c, Location__c From Conference__c Where Type_of_Technology__c  = '{!Conference__c.Type_of_Technology__c}']));
}
return setCon;
}
set;
}
public List<Conference__c> getConferences() {
return (List<Conference__c>) setCon.getRecords();
}
}

 

Apex Page markup:

 

<apex:page controller="similarConferences" sidebar="true">
  <apex:variable value="{!Conference__c}" var="con"/>
    <apex:pageBlock title="Similar Conferences">
      <h1>This page summarizes all conferences promoting {!con.Type_of_Technology__c} technology!</h1><br>
      <apex:outputLabel value="Total {!con.Type_of_Technology__c} Conferences: "/>
       <apex:pageBlockSection title="Conference List">
           <apex:dataTable value="{!Conference__c}" var="con" id="theTable">
               <apex:column id="firstColumn">
               <b><apex:outputLabel value="Name"/></b><br>
               <apex:outputText value="{!con.name}"/>
               </apex:column></br>
               <apex:column id="secondColumn">
               <b><apex:outputLabel value="Date"/></b><br>
               <apex:outputText value="{!con.Conference_Date__c}"/>
               </apex:column>
               <apex:column id="thirdColumn">
               <b><apex:outputLabel value="Location"/></b><br>
               <apex:outputText value="{!con.Location__c}"/>
               </apex:column>
           </apex:dataTable>       
       </apex:pageBlockSection></br>
    </apex:pageBlock>
</apex:page>

 

Any help is greatly appreciated.

 

Thanks,

S Ryan

Best Answer chosen by Admin (Salesforce Developers) 
sryansryan

I've finally solved the issue.  I had previously built the functionality in SControl and tried to use the same approach to the SOQL in Apex.  This, of course, did not work because calling variables in Apex requires that they are binded.  I accomplished this through using the colon notation for the variable I was calling in the embedded SOQL, i.e. ":conferences.Type_of_Technology__c" and it worked fine.

 

Thanks for your help, michaelforce.

sryan

All Answers

michaelforcemichaelforce

sryan, the error you described is because there is no matching "get" method for a variable you are trying to reference in the markup... more specifically, you actually do have a "get" method (getConferences)... but the name doesn't match what you are calling it in your markup (Conference__c).

 

Try changing the "value" attribute in your dataTable to be "{!Conferences}".  Also, the variable tag on line 2 will need to be changed or removed.

sryansryan

Michael - I appreciate your help.  I got the markup working (kind of) based on your suggestion.  I tested the markup and controller code using a static value for the where clause in the SOQL statement and it returned the correct type and number of itmes in a list.  You have definitely helped me gain a better understand of calling methods contained within specified controllers.  However, I am unable to see the VF Page using this controller when I try to implement it within the Conference__c (custom object) as a custom link.  I'm guessing that this is because it is not a standard controller, or I have not correctly associated it to the Conference__c custom object.  So I'm wondering if there is a way to configure the controller so that I make an association for a given custom object (in this case Conference__c), or would this be more effectively achieved by writing a controller extension for a standard controller so that I can see the VF Page within the Conference__c cusotm obeject ?

 

Again, thanks very much for the hlep.  Your (or others) suggestions are greatly appreciated.

 

Regards,

SRyan

sryansryan

The revised Apex code with statis value:

public class similarConferences { public static ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select Name, Conference_Date__c, Location__c, Type_of_Technology__c From Conference__c Where Type_of_Technology__c = 'Java'])); } return setCon; } set; } public List<Conference__c> getConferences() { return (List<Conference__c>) setCon.getRecords(); } }

 

 

The revised VF markup:

<apex:page controller="similarConferences"> <apex:pageBlock title="Similar Conferences"> <apex:pageBlockSection title="Conference List"> <apex:dataTable value="{!Conferences}" var="conf" id="theTable" border="row" width="900"> <apex:column id="firstColumn" width="200"> <b><apex:outputLabel value="Name"/></b><br></br> <apex:outputText value="{!conf.name}"/> </apex:column> <apex:column id="secondColumn" width="200"> <b><apex:outputLabel value="Date"/></b><br></br> <apex:outputText value="{!conf.Conference_Date__c}"/> </apex:column> <apex:column id="thirdColumn" width="200"> <b><apex:outputLabel value="Location"/></b><br></br> <apex:outputText value="{!conf.Location__c}"/> </apex:column> </apex:dataTable> </apex:pageBlockSection> </apex:pageBlock> </apex:page>

 

sryansryan

MichaelForce - I've been tweaking the code to try and get the result  seek, but thus far have not found the right syntax.  I revised the Apex Class code and VF markup to use a standardController extension.  It works when I provide a static value for the field 'Type_of_Technology__c' (i.e. 'Java'), but it does not work when I set the value equal to a variable, in this case '{!Type_of_Technology__c} (hilighted in red in the code below).  I'm pretty sure that I'm close, but something is not right with my SQL query that is being called using the Database.QueryLocator method.

 

The Apex Class for the Controller Extension using current variable:

public class conferenceExtension { private final Conference__c conference; // The extension constructor initializes the private member // variable conference by using the getRecord method from the standard // controller. public conferenceExtension(ApexPages.StandardController stdController) { this.conference = (Conference__c)stdController.getRecord(); } public static ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select Name, Conference_Date__c, Location__c, Type_of_Technology__c From Conference__c Where Type_of_Technology__c = '{!Type_of_Technology}'])); } return setCon; } set; } public List<Conference__c> getConferences() { return (List<Conference__c>) setCon.getRecords(); } }

 

The Apex Page markup:

 

<apex:page standardController="Conference__c" extensions="conferenceExtension" sidebar="true"> <apex:variable value="{!Conference__c}" var="con"/> <apex:pageBlock title="Similar Conferences"> <h1>This page summarizes all conferences promoting {!con.Type_of_Technology__c} technology!</h1><br> <apex:outputLabel value="Total {!con.Type_of_Technology__c} Conferences: "/> <apex:pageBlockSection title="Conference List"> <apex:dataTable value="{!Conferences}" var="c" id="theTable" border="all" width="900"> <apex:column id="firstColumn" width="200"> <b><apex:outputLabel value="Name"/></b><br></br> <apex:outputText value="{!c.name}"/> </apex:column> <apex:column id="secondColumn" width="200"> <b><apex:outputLabel value="Date"/></b><br></br> <apex:outputText value="{!c.Conference_Date__c}"/> </apex:column> <apex:column id="thirdColumn" width="200"> <b><apex:outputLabel value="Location"/></b><br></br> <apex:outputText value="{!c.Location__c}"/> </apex:column> </apex:dataTable> </apex:pageBlockSection> </br></apex:pageBlock> </apex:page>

 

I would apprecaite any hints or ideas for sovling this.

 

Thanks in advance.

 

sryan

VF with empty list

sryansryan

I've finally solved the issue.  I had previously built the functionality in SControl and tried to use the same approach to the SOQL in Apex.  This, of course, did not work because calling variables in Apex requires that they are binded.  I accomplished this through using the colon notation for the variable I was calling in the embedded SOQL, i.e. ":conferences.Type_of_Technology__c" and it worked fine.

 

Thanks for your help, michaelforce.

sryan

This was selected as the best answer