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
logontokartiklogontokartik 

Get Field Name API in Visualforce

Is there a way to get the API field name via Dynamic Bindings in Visualforce? I am able to get the Label, but its not allowing me to get the actual API Name. 

 

I need this to dynamically list columns on VF Page and allow them to toggle a Sort.

 

Below is code snippet: One in red is giving me error. 

 

 

 <apex:repeat value="{!columnFieldsList}" var="flds">                 
<apex:column > 
   <apex:facet name="header">
<apex:commandLink action="{!toggleSort}" value="{!$ObjectType.Location__c.Fields[flds].Label}" rerender="locationdata">
<apex:param name="sortField" value="{!$ObjectType.Location__c.Fields[flds]}" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet> 
<apex:outputField value="{!l.loc[flds]}" style="width:30%;"/>
</apex:column> 
</apex:repeat>
Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Correct me if I'm wrong, but isn't flds the API name? I mean, how else would you be retrieving the field's label except by its API name? It seems to me that {!flds} should work just fine.

All Answers

sfdcfoxsfdcfox

Correct me if I'm wrong, but isn't flds the API name? I mean, how else would you be retrieving the field's label except by its API name? It seems to me that {!flds} should work just fine.

This was selected as the best answer
logontokartiklogontokartik

I think I am being silly not trying what you said. Yes you are right, I can use {!flds} to get the fieldname back to the controller. 

VF Dynamic Binding rocks!!!!

 

Thanks fox....