1

I'm am trying to use Salesforce's wire service to return schema information for an external object.

js:

import { LightningElement, track, wire, api } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
import { fireEvent } from 'c/pubsub';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import MYEXTERNAL_OBJECT from '@salesforce/schema/MyExternal__x';

export default class CampaignCriteria extends LightningElement {
    @track objectInfo;
    @track errors;
    @wire(getObjectInfo, {objectApiName: MYEXTERNAL_OBJECT}) objectInfo;

    get objectInfoStr() {
        return this.objectInfo ? 
                 JSON.stringify(this.objectInfo.data,null,2): '';
    }

    get objectErrors() {
        return this.objectInfo ? 
               JSON.stringify(this.objectInfo.error,null,2): '';
    }
}

html:

<template>
    <lightning-card>
        <h3 slot="title">
            Campaign Criteria
        </h3>
        <template if:true={objectInfo.data}>
            <div class="scroller">
                <pre>{objectInfoStr}</pre>
            </div>
        </template>
        <template if:true={objectInfo.error}>
            <pre>{objectErrors}</pre>
        </template>
    </lightning-card>

</template>

When the component is loaded, I'm getting a 403 error.

{
  "ok": false,
  "status": 403,
  "statusText": "INSUFFICIENT_ACCESS",
  "body": [
    {
      "errorCode": "INSUFFICIENT_ACCESS",
      "message": "You don't have access to this record. Ask your administrator for help or to request access."
    }
  ]
}

If I replace MYEXTERNAL_OBJECT with a standard Salesforce object, it works fine. I've checked permissions (I'm logged in as System Administrator) and everything seems fine. Any ideas?

  • Can you use workbench and see if you have access to that object or not? also, check Deployment Status – Avijit Chakraborty Nov 5 '19 at 2:10
  • Hi there @AvijitChakraborty. I'm able to access the object's and fields' information in Workbench. I don't have any deployments pending or failed. – blastocyst.jones Nov 5 '19 at 14:49
  • 1
    hello, were you able to resolve this problem?. I'm facing the same problem, and only retrieving by {listViewId : LIST_VIEW_ID} seems to work for external objects. – andrea Jan 29 at 16:54
  • Hi @andrea . I was able to get this to work. The issue seems to be with the import statement. Instead of importing from the schema, I just plugged the external object's name into the wire call. So, @wire(getObjectInfo, {objectApiName: 'MyExternal__x'}) objectInfo; See if that works for you. – blastocyst.jones Jan 30 at 19:51

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.