[SalesForce] way to load every label data and every SObject description data in Lightning Web Component using only Javascript without any Apex

Is there a way to load every label data and every SObject description data using only Javascript without any Apex Server-side code?

How do I import * from @salesforce/schema or @salesforce/label?

I am looking for a way to get all labels or all SObject describe information details to retrieve in LWC at once.

I can see that such syntax is provided by ES6 and is used widely by Salesforce itself, however, it is not possible to use the following syntax in LWC:

 import * as schema from '@salesforce/schema' 
 import * as label from '@salesforce/label'

or this syntax

import {label, schema} from '@salesforce';

since both versions generate error

LWC1512: Missing resource value for @salesforce"

or

LWC1512: Missing resource value for @salesforce/label

Is there a way to load every label data and every SObject description data using only Javascript without any Apex Server-side code?

By the way, if we look as Salesforce Playground we could notice that
enter image description here
the same syntax is used to import everything from lwc

import * as Engine from 'lwc';

however, if we try to insert such line into any of Lightning Web Component, we would receive the following error

LWC1001: Invalid import. Namespace imports are not allowed on "lwc",
instead use named imports "import { LightningElement } from 'lwc'"
or
LWC1517: Invalid LWC import

Best Answer

An ES6 module is a JavaScript file that explicitly exports variables or functions that other modules can use. Modules make it easier to structure your code without polluting the global scope.

Everything in LWC which is imported and Exported is a ES6 module.

JavaScript files in Lightning web components are ES6 modules. By default, everything declared in a module is local—it’s scoped to the module.

As this is basically es6 and not just LWC, I tried searching import all from es6.

Surprisingly, there are many results, I tried a solution from most accepted and most voted answer that suggested exporting * first and then importing it in new component.

My code which exports all lables in AllLables module

import { LightningElement } from 'lwc';
export * from '@salesforce/label';


export default class AllLables extends LightningElement {

}

when I try saving it, I get this error:

LWC1507: Exporting * from @salesforce/label is not allowed.

Apparently, even if there is the way in ES6, SF is intentionally blocking it, probably for the same reason it does not allow SELECT * in SOQL

You have to use Apex :(

Related Topic