0

I am trying to use the Salesforce Object Query Language (SOQL), and the Salesforce Object Describe API to import the objects and fields data into my JavaScript file. I am a bit lost on where to start, as I don't know if I am retrieving the object metadata correctly. Also for SOQL would this be done in my JavaScript file? I don't know where to start with SOQL, since I am unsure If I am getting any metadata from my object.

Here's my code for the Salesforce Object Describe API

// Importing Opportunity object and fields metadata.
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import OPPORTUNITY_OBJECT from '@salesforce/schema/Opportunity';

// -----------------------------------------------------------------------------

export default class Mapping extends LightningElement {

    @wire(getObjectInfo, { objectApiName:  OPPORTUNITY_OBJECT })
    propertyOrFunction;

Question on my code: I guess my question for this is if I am missing anything when using the wire adapter to get metadata for my object? Also which variable is the metadata stored in? is it the 'OPPORTUNITY_OBJECT' or 'propertyOrFunction'?

My Output for 'propertyOrFunction'

enter image description here

1 Answer 1

1

I guess my question for this is if I am missing anything when using the wire adapter to get metadata for my object?

You will have loaded your metadata after the first renderedCallback() completes, meaning you can't use the data in connectedCallback() because it isn't present yet, at least without using asynchronous code.

Also which variable is the metadata stored in? is it the 'OPPORTUNITY_OBJECT' or 'propertyOrFunction'?

OPPORTUNITY_OBJECT is a simple object that will look like this:

{
   objectApiName: 'Opportunity'
}

Your metadata will appear in propertyOrFunction, and you will access it through this.propertyOrFunction.data after the metadata has loaded.

You'll want to look at the Object Info documentation for the properties that will be available.

5
  • I was referencing the 'getObjectInfo' developer guide, and didn't see anything on renderedCallback() or connectedCallback(). Are they built in functions needed or methods that I should create?
    – Pinto
    Apr 12 at 17:06
  • @Pinto They're part of the lifecycle hooks in LWC, and I explained how they interact with wire. By the way, this kind of looks like an X-Y Problem, thinking about it. What is your end goal, the reason why you started down this path?
    – sfdcfox
    Apr 12 at 17:36
  • My goal is to get the metadata for all my Opportunities in Salesforce (the address, city, and state). So I can map out every Opportunity in the lightning-map. Should I use the wire adapter to get metadata for my Opportunity object, or is that in the wrong direction?
    – Pinto
    Apr 12 at 17:49
  • 1
    @Pinto Geolocating addresses is limited to 10 per map. That's going to be your main limitation. Aside from that, you can query this data directly from Apex, and return the values to the LWC for whatever purpose you need. Normally, you only need the getObjectInfo API if you plan on rendering your own layout or something.
    – sfdcfox
    Apr 12 at 18:14
  • Ok thanks for the heads-up, I'll look into querying the data directly from Apex.
    – Pinto
    Apr 12 at 18:27

You must log in to answer this question.

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