I am creating a LWC that handles data from an external object. I have access to the recordId through @api recordId;, but I need to get the externalId from this object as well.

Currently, I have call to an APEX class that simply returns the ExternalId of that record.

public with sharing class EnterpriseCaseHandler {
     public static String getCaseRecordID(ID currentRecordId){
        return [SELECT ExternalId FROM EntCase__x WHERE id= :currentRecordId LIMIT 1].ExternalId; 

While this works, I am wondering if there is a way to eliminate this call and get the field value of ExternalId directly from the record.

I am trying to follow this documentation: https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_get_field_value

Is there support for external objects? I may have the schema incorrect, just not sure how to determine what it should be.

Here is my code:

import { LightningElement, track, api, wire } from "lwc";
import { getRecord, getFieldValue } from "lightning/uiRecordApi";
import EXTERNAL_ID from "@salesforce/schema/EntCase__x.ExternalId"; // External Object

const fieldValues = [EXTERNAL_ID];

export default class ChatterData extends LightningElement {

   * Get the field values for this external case record
  @wire(getRecord, { recordId: "$recordId", fieldValues })

   * Get the externalId for this case record
  get externalId() {
    return getFieldValue(this.entCase.data, EXTERNAL_ID);

  renderedCallback() {
    let external = getFieldValue(this.entCase.data, EXTERNAL_ID);
    console.log(external) // returns {}
    console.log(this.entCase.data) // returns {} 
    console.log(this.entCase) // returns {}

  • I don't have external objects in my org to test against, but I wouldn't be too optimistic about being able to use the UI API here (see docs: developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/…). The syntax mostly looks all right, except it does occur to me that renderedCallback() might execute before your wired record is populated. What happens if you put <p>{externalId}</p> somewhere in the template? If you don't see it then, I would go back to Apex. – Matthew Souther Dec 9 '19 at 17:22
  • 2
    @MatthewSouther - Bummer, I tried that as well using the getter and it didn't display. I added an error callback to my @wire and got a response of aura_prod.map.js:41912 {"ok":false,"status":500,"statusText":"Internal Server Error","body":{"errorCode":"INVALID_FIELD","message":"Entity name for the provided record didn't match required field EntCase__c.ExternalId","stack":"Error: Entity name for the provided record didn't match required field EntCase__c.ExternalId\n . Looks like it is trying to use EntCase__c vs EntCase__x. Doesn't appear to support external objects from what I can tell – SBB Dec 9 '19 at 17:30

Your Answer

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

Browse other questions tagged or ask your own question.