0

All Fields label are getting in this list but i don't want ID field from below code how to avoid ID field label.

public List<String> AllLabels{get;set;}
 String type='Account';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(type);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();

for (String fieldName: fieldMap.keySet()) {

 System.debug('##Field API Name='+fieldName);// list of all field API name
 AllLabels.add(fieldMap.get(fieldName).getDescribe().getLabel());
}
3
  • What do you mean by how to avoid ID field label, do you want to filter out lookup fields; or get rid of Id from label such that Account Id becomes Account – Raul Mar 28 '19 at 11:26
  • I am getting this error if i bind ALLLabels List on vf page Could not resolve field 'Record ID' from <apex:inputField> value binding '{!sobj[headerApiName]}' in page CongiProMiles – cloudZigZag Mar 28 '19 at 11:28
  • 1
    Looks like XY problem, could you please share a minimum version of code for someone to look and help you further. The code and information you've provided in the question is incomplete. – Raul Mar 28 '19 at 11:36
2

Based on your comment:

if i bind ALLLabels List on vf page Could not resolve field 'Record ID' from <apex:inputField> value binding '{!sobj[headerApiName]}' in page CongiProMiles

I'm pretty sure what's happening is this:

  1. You're creating a List<String> of all of the field labels on an object, in the code you've shown us in your question.
  2. You are attempting to iterate over that List to create <apex:inputField> components bound to the actual field values on an sObject instance.

The issue, then, is that you're trying to access field values by subscripting their labels, not their API names. "Record ID" is the label for the field whose API name is Id. You can't ask an sObject for its "Record ID" field; you must specify the API name.

You need to be using API names anywhere you're doing value binding. If you also want to display the field label, you may need to create additional data structures to map the API name to the label so Visualforce can access it.

1
  • yes, alernate option is creating fieldset and use on the visualforce page – cloudZigZag Mar 28 '19 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.