0

As a learning exercise I wanted to build a visual force page to display a dynamic value. The dynamic value will have code around it in the class. Right now I just want to display it on the Page not as a field. While trying to display the value. Yes I know that i could easily display the name column on the page a different way but I know that i can display it like the below.... I am getting an error of "Could not resolve field 'strGetName' from value binding '{!objVF['strGetName']}' in page myvfpage "

Below is my code

Public with sharing Class MYClass {

public MYClass(ApexPages.StandardController controller) {
    MyPagesObjects();
}
Public SObject objVF {get;private set;}

Public void MyPagesObjects()
{
    //Gets the ID of the current Page
     System.debug(LoggingLevel.ERROR, 'DEBUG  ');
    String MyObjectID = ApexPages.currentPage().getParameters().get('id');
    System.debug(LoggingLevel.ERROR, 'DEBUG  ' + MyObjectID);

    String GetMyObjectsQuery = 'SELECT Name, Checkbox__c FROM Object_1__c where id =  \'' + MyObjectID + '\'';

    objVF = Database.query(GetMyObjectsQuery);

    String strGetName = ''+ objVF.get('Name');

    System.debug(LoggingLevel.ERROR, 'DEBUG  ' + strGetName);        
}

}//end class

VF

<apex:page standardcontroller="Object_1__c" extensions="MYClass" sidebar="false"  docType="html-5.0" action="{!MyPagesObjects}">
<apex:form >
<apex:outputLabel >"MYValue"</apex:outputLabel>
 <apex:pageblock mode="maindetail">
<apex:pageblocksection title="MY Visual Force Page" showheader="true" collapsible="true" columns="1">
    <apex:pageblocksectionitem >
         <apex:outputlabel value="Owner"/>
        <apex:outputpanel >
        <apex:outputfield value="{!objVF['strGetName']}"/>
        </apex:outputpanel>            
    </apex:pageblocksectionitem>
</apex:pageblocksection>
    </apex:pageblock>
</apex:form>

1 Answer 1

1

strGetName needs to be a public variable, and you do NOT want to use quotes around the name; this makes it a literal string (i.e. you're trying to read a field named strGetName).


Public with sharing Class MYClass {
  public string strGetName { get; set; }
  ...
  strGetName = ''+objVF.get('Name');
  ...
}

<apex:outputfield value="{!objVF[strGetName]}"/>

In addition, I suspect that you are simply trying to show the value? In that case, you wouldn't use apex:outputField, but instead just show the variable itself:

<apex:outputText value="{!strGetName}" />
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .