I am trying to import a custom object and I am getting the following error
‘LWC1513: @salesforce/schema modules only support default imports’
here is my code for my js file.
import { LightningElement,api } from 'lwc'; import { StreetAddress } from "@salesforce/schema/Retail_Account__c.Address__c"; import { CityAddress } from "@salesforce/schema/Retail_Account__c.City__c"; import { StateAddress } from "@salesforce/schema/Retail_Account__c.State__c"; import { RetalName } from "@salesforce/schema/Retail_Account__c.Name" export default class RetailMapSingleMarker extends LightningElement { @api RecordId @api objectApiName mapMarkers = [ { location: { Street: StreetAddress, City: CityAddress, State: StateAddress, }, title: RetalName , }, ]; }
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
When you say import { RetalName }
– this is called Named Import. This is not valid for @salesforce/schema modules since they are default exports. You need to use below:
import RETAIL_ACCOUNT_NAME from "@salesforce/schema/Retail_Account__c.Name"
This means, you are importing default Retail_Account__c.Name
and assigning it to variable RETAIL_ACCOUNT_NAME
.
NOTE:
You can use Named imports for a module like below:
const getTermOptions = () => { return [ { label: '20 years', value: 20 }, { label: '25 years', value: 25 }, ]; }; const calculateMonthlyPayment = (principal, years, rate) => { // Logic }; export { getTermOptions, calculateMonthlyPayment };
Here, you are exporting getTermOptions and calculateMonthlyPayment functions. So, you can import them by Name as below.
import { getTermOptions, calculateMonthlyPayment } from 'c/your_module'
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0