I have a custom object C.
It has two fields F1__c
and F2__c
.
In my controller there is a String s
.
The s
contains "F1__c
"
Will it be possible for me to display this field whose API name is contained in the variable s
?
public xyzcontroller
{
public String s{get;set;}
public xyzcontroller()
{
s = "F1__c";
}
}
UPDATE
I tried following Vamsi's answer but no luck.
Here is my actual VF/Controller
VF Page
<apex:page Controller="TestXXXController" showHeader="false" sidebar="false">
<apex:form id="theform">
<h2>Questions</h2>
<apex:outputField value="{!pr.get(varstr)}"/>
</apex:form>
</apex:page>
Controller
public class TestXXXController {
public XXX__c pr{get;set;}
public String varstr{get;set;}
public TestXXXController()
{
init();
}
public void init()
{
XXX__c p = new XXX__c();
String queryStr = 'Select '+CommonUsedClass.sObjectGetAllFields(p).trim()+' FROM XXX__c LIMIT 1';
List<XXX__c> plist = new List<XXX__c>();
plist = Database.query(queryStr);
pr = plist[0];
System.debug('p == > '+ pr);
varstr = 'Schema.XXX__c.Name';
}
}
The above VF page gives me compile error as shown below
Could not resolve field 'get(varstr)' from <apex:outputField> value binding '{!pr.get(varstr)}' in page TestXXX1