I'm creating a LWC (lightning web component) which allows any field to be displayed of any field type for any object, and to drop these into a flow page.

I've run into a problem, where, I'd like to do something like this (AND THIS CODE WORKS - it is the next block of code that does not work)

import { getObjectInfo } from 'lightning/uiObjectInfoApi';
@wire(getObjectInfo, {objectApiName:{ "objectApiName": "Account"}})  })
// note would have default attribute set but this is not supported in flow

and in the xml I have something like this

        <targetConfig targets="lightning__FlowScreen">
            <property name="objectName" type="String"></property>...

But I've not got anywhere with this, because the objectName in the controller is coming as undefined?{objectName} in the template code, it displays as correctly configured in the component meta-data "Account". Really, this is driving me nuts and seems like something I should be able to do:

@api objectName;
@wire(getObjectInfo, {objectApiName:{ "objectApiName": '$objectName'}}) 

But when I do this, I just receive the following coming back from the wire: 403 access denied

Because the value being sent via the call, as I can see in network logs, it is sending literally "$objectName" instead of even undefined or, what I'd really like - "Account".

Do I need to something to wait, for this $objectName to be set before calling wire? Surely @wire should notice the change, which eventually it does have because I can see in the UI-- and then load the right data??

  • You need to give the object API name in a specific format, which should be { apiName: 'object-api-name-here'} – Rahul Gawale Jul 30 '20 at 15:03
  • ... the first block of code works, and the second does not, the issue is with the $objectName not with the format. – picklenic Jul 30 '20 at 15:22

Your format of wire adapter seems to have an error where you are passing it an Object instead of the String. It should be either be

@wire(getObjectInfo, { objectApiName: '$objectName' }) objectInfo;

Please see these docs:


import { LightningElement, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class Example extends LightningElement {
    @track objectName = 'Account'
    @wire(getObjectInfo, { objectApiName: '$objectName'})
  • Yeah, the issue is I'm not wanting to use the example, I have used the docs. We want something generic here, and passing the string, only will cause an error because when you pass ACCOUNT_OBJECT in this example, it is passing the schema of the Account i.e. an object {"objectApiName": "Account"} and hence, my attempt to copy this. And, when I do this as I just said it works- but what does not work, is the $objectName variable. – picklenic Jul 30 '20 at 15:20
  • Would you be able to explain what you mean when you say passing a string will cause an error? The example above uses a reactive string and works just fine. – manjit5190 Jul 30 '20 at 15:34
@api objectName;
    @wire(getObjectInfo, {objectApiName: '$objectWithApiName'}) 
    objectInfo({ error, data...

then ensure there is a getter with a different named var than your @api public variable (this was key lol)

get objectWithApiName() {
        return { objectApiName: this.objectName };

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.