4

When creating custom fields on external objects you have the ability to add "External Alias / External Column Name" of the corresponding field name in the external data source.

enter image description here

I've got a situation where I need a way to find out the corresponding external column name based on the field API name (in APEX) in order to make things easier, though I couldn't find anything in the DescribeFieldResult Class nor had any luck with Workbench...

I thought about having a Custom Settings "Map", but that seems like an overkill for something that should be there out of the box.

Wondering whether I am missing something and/or if anyone has a better approach.

4

You can retrieve this using the Tooling API by using the externalDeveloperName attribute of the Metadata returned from:
/services/data/v39.0/tooling/sobjects/CustomField/[your field id]

Alternatively, if you don't know the field ID you can use the query endpoint,the only issue with this is that if you want to return the Metadata field you must ensure that your query only returns a single result, so you'll probably want to filter on TableEnumOrId as well as the DeveloperName of your field:
/services/data/v39.0/tooling/query?q=SELECT+Metadata+FROM+CustomField+WHERE+DeveloperName=[your field API name]+AND+TableEnumOrId=[your table enum/id]

Example response:

{
  "size" : 1,
  "totalSize" : 1,
  "done" : true,
  "queryLocator" : null,
  "entityTypeName" : "CustomField",
  "records" : [ {
    "attributes" : {
      "type" : "CustomField",
      "url" : "/services/data/v39.0/tooling/sobjects/CustomField/00N0Y00000ByqwZUAR"
    },
    "Metadata" : {
      "caseSensitive" : null,
      "customDataType" : null,
      "defaultValue" : null,
      "deleteConstraint" : null,
      "deprecated" : null,
      "description" : "icon",
      "displayFormat" : null,
      "displayLocationInDecimal" : null,
      "encrypted" : null,
      "escapeMarkup" : null,
      "externalDeveloperName" : "icon",
      "externalId" : false,
      "formula" : null,
      "formulaTreatBlanksAs" : null,
      "inlineHelpText" : null,
      "isConvertLeadDisabled" : null,
      "isFilteringDisabled" : false,
      "isNameField" : false,
      "isSortingDisabled" : false,
      "label" : "icon",
      "length" : 255,
      "lookupFilter" : null,
      "maskChar" : null,
      "maskType" : null,
      "metadataRelationshipControllingField" : null,
      "populateExistingRows" : null,
      "precision" : null,
      "readOnlyProxy" : null,
      "referenceTargetField" : null,
      "referenceTo" : null,
      "relationshipLabel" : null,
      "relationshipName" : null,
      "relationshipOrder" : null,
      "reparentableMasterDetail" : null,
      "required" : false,
      "restrictedAdminField" : null,
      "scale" : null,
      "startingNumber" : null,
      "stripMarkup" : null,
      "summarizedField" : null,
      "summaryFilterItems" : null,
      "summaryForeignKey" : null,
      "summaryOperation" : null,
      "trackFeedHistory" : null,
      "trackHistory" : null,
      "trackTrending" : null,
      "type" : "Text",
      "unique" : false,
      "urls" : null,
      "valueSet" : null,
      "visibleLines" : null,
      "writeRequiresMasterRead" : null
    }
  } ]
}
| improve this answer | |

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.