I have created a namespaced scratch org from a DevHub org. I can see the namespace prefix for fields, objects and apex in the scratch org. We have few LWC component as well in the package where I need to add the namespaces in the code in order to work.


    this.sectionRelatedData.forEach((element, index) => {
        if (this.sectionId == element.sectionId) {
            element.sectionName = this.sectionVal;
            let field = {}
            field['Id'] = this.sectionId;
            field['EventTechHub__Section_Name__c'] = element.sectionName;
            const recordInput = {
                fields: field
                .then(() => {
                    this.showToast('Success!!', 'Updated successfully!!', 'success');
                .catch(error => {
                    this.showToast('Error!!', error.body.message, 'error');

In the above code we have to add the namespace prefix "EventTechHub__" in order for it to work.

Is there any way to get rid of hardcoded namespace for development?

2 Answers 2


Import your fields, and use the relevant tokens:

import EVENT_SECTION_NAME from "@salesforce/schema/Event_Section__c.Event_Section_Name__c";
field[EVENT_SECTION_NAME.fieldApiName] = element.sectionName;

Salesforce will automatically provide the namespace, or not, depending on the context.


There are two ways to fetch the namespace dynamically:

  1. Create a Global variable in any one of the class to store the namespace

  2. Use the wire method to fetch the object info and namespace

    @wire(getObjectInfo, { objectApiName: 'EventTechHub__Section__c' })

    get namespace() {
        return this.objectInfo.data ? this.objectInfo.data.namespace : '';

You must log in to answer this question.

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