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 :(
added based on comments
It seems there is a bug for importing geolocation fields (able to import other compound fields like BillingCity). So, we can use direct string notation as below.
Geolocation
type fields are Compound Fields (like BillingAddress
). Two main points to be highlighted from docs is :
Geolocation is a compound field that counts toward your org’s limits
as three custom fields: one for latitude, one for longitude, and one
for internal use. Support for the compound field (geolocation) versus
the field’s components (latitude and longitude) varies depending on
the functionality you’re using in Salesforce. For example, you can
create list views that show the field and its components, but you
can’t select the compound geolocation field in Apex. You can run SOQL
queries only on a geolocation field’s components.
Compound fields are accessible only through the SOAP and REST APIs.
The compound versions of fields aren’t accessible anywhere in the
Salesforce user interface.
Below is the working sample code:
import { LightningElement, wire, api, track } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
export default class Poc extends LightningElement {
@api recordId;
@wire(getRecord, {
recordId: '$recordId',
fields: [ 'Account.Acc_Location__Latitude__s', 'Account.Acc_Location__Longitude__s' ]
})
wiredAcc({ data, error }) {
console.log('Account => ', JSON.stringify(data), JSON.stringify(error));
}
}
and its output:
{
"apiName": "Account",
"childRelationships": {
},
"fields": {
"Acc_Location__Latitude__s": {
"displayValue": null,
"value": 1.2345678
},
"Acc_Location__Longitude__s": {
"displayValue": null,
"value": 2.3456789
}
},
"id": "00128000009j45sAAA",
"lastModifiedById": "00528000001IIBvAAO",
"lastModifiedDate": "2019-08-25T14:37:49.000Z",
"recordTypeInfo": null,
"systemModstamp": "2019-08-25T14:37:49.000Z"
}
Note that you should ideally use imported fields instead of direct strings in parameter
Best Answer
Use single-quotes (which is a Prettier setting).