0

here the sObjectType is of Account type

 Map<String, Schema.SObjectField> fieldMap = sObjectType.getDescribe().fields.getMap();

 for (String fName: fieldMap.keySet()) 
    System.debug('Field Name '+ fName + ' Label '  +fieldMap.get(fName).getDescribe().getLabel() );

in Salesforce account object field name for phone is Phone and lable is also Phone but when I try to access it using above method it shows field name as Phone and label as Account Phone

screenshot of my logs

enter image description here

Not sure why it is happening this way

screenshot of account from Salesforce

enter image description here

While accessing it using Tooling API it shows the correct label

SELECT EntityDefinition.QualifiedApiName,FieldDefinition.DataType,FieldDefinition.Label,FieldDefinition.QualifiedApiName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName IN ('Account')

screenshot of result fetched using Tooling API

enter image description here

1 Answer 1

1

The case is that for import wizard you use as much accurate labels as possible, so the label shown by fieldMap.get(fName).getDescribe().getLabel() is guarantee that when fields are mapping they will not overlap.

What I mean, is that you have Phone field label in Lead, Account, Contact and so on.

Here is the documentation that matches .getLabel() with actual label that is shown in UI.

https://help.salesforce.com/articleView?id=field_mapping_for_other_data_sources_and_organization_import.htm&type=5

Account Phone -> Account: Phone

2
  • But don't you think it may confuse user as we are using standard field labels so that they don't think that Phone and Account Phone are two different fields. I guess alternate way is to use Tooling API what you think
    – Hunt
    Commented Oct 10, 2019 at 10:04
  • Yes, sure, if it suits you. I've just explained why there is the difference. Commented Oct 10, 2019 at 10:53

You must log in to answer this question.

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