We are writing LWC component which is a part of our managed package. And there is a need to have package namespace available in javascript variable there for further manipulation etc.

Is there any way to get current package namespace in LWC component without calling server-side method? Any help would be appreciated.

1 Answer 1


You can import fields in LWC:

import SAMPLE_FIELD from '@salesforce/schema/SampleObject__c.SampleField__c';

Imported fields get namespaces automatically by salesforce:

SAMPLE_FIELD.fieldApiName; // NAMESPACE__SampleField__c

you can just get the namespace from the field, this also works for objects.

You must log in to answer this question.

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