0

tl;dr - How can one successfully validate an LWC via a change set that contains schema imports to a custom metadata type?

Problem

I have a working LWC in a sandbox, and am attempting to port it to production via a change set. However, the portion of the LWC that imports a custom metadata type and it's fields causes an error in the change set validation. The validation error message (listed below) appears identically six times, I believe one for each of my Custom Metadata schema imports.

Attempted Solutions

I've tried importing any updates to the custom metadata in a separate change set (which deployed successfully), thinking that an update there may have cause the error, to no effect. I've also searched online for similar issues but have had difficulty finding any posts that describe this issue.

Question

How can I import an LWC via a change set that contains a schema import to custom metadata?

Code

LWC Javascript

import { LightningElement, track, wire } from "lwc";

// // Schema Imports
// Global_Mapping__mdt
import OBJECT_GLOBAL_MAPPING from "@salesforce/schema/Global_Mapping__mdt";
import GLOBAL_MAPPING_FIELD_KEY from "@salesforce/schema/Global_Mapping__mdt.Key__c";
import GLOBAL_MAPPING_FIELD_VALUE from "@salesforce/schema/Global_Mapping__mdt.Value__c";
import GLOBAL_MAPPING_FIELD_SECONDARY_VALUE from "@salesforce/schema/Global_Mapping__mdt.Secondary_Value__c";
import GLOBAL_MAPPING_FIELD_PROJECT from "@salesforce/schema/Global_Mapping__mdt.Project__c";
import GLOBAL_MAPPING_FIELD_MAP from "@salesforce/schema/Global_Mapping__mdt.Map__c";

Deployment Validation Error Message

Invalid reference Global_Mapping__c.Value__c of type sobjectClass in file getFeedbackInterface.js 
Invalid reference Global_Mapping__c.Key__c of type sobjectClass in file getFeedbackInterface.js 
Invalid reference Global_Mapping__c.Map__c of type sobjectClass in file getFeedbackInterface.js 
Invalid reference Global_Mapping__c.Secondary_Value__c of type sobjectClass in file getFeedbackInterface.js 
Invalid reference Global_Mapping__c.Project__c of type sobjectClass in file getFeedbackInterface.js 
Invalid reference Global_Mapping__c of type sobjectClass in file getFeedbackInterface.js

enter image description here

2
  • Can you import custom metadata with @salesforce/schema? I see the docs mention that only standard and custom objects can be imported -- "Lightning Web Components supports the import of references to standard objects, as well as the import of references to custom objects (__c) only". Does this code work?
    – Jayant Das
    Jul 2, 2021 at 3:00
  • The code does work in my sandbox without issue, that's the confounding element here.
    – Jwok
    Jul 2, 2021 at 15:19

1 Answer 1

1

For future readers, I was not able to figure out why custom metadata imports worked in my sandbox but not in production. I changed the offending lines as follows to get it through change set validation, although I'm still hoping that someone will be able to figure out a means of custom metadata import that doesn't rely on hard-coding.

// // Schema Imports
// [Values commented out due to error in change set]
// Global_Mapping__mdt
// import OBJECT_GLOBAL_MAPPING from "@salesforce/schema/Global_Mapping__mdt";
// import GLOBAL_MAPPING_FIELD_KEY from "@salesforce/schema/Global_Mapping__mdt.Key__c";
// import GLOBAL_MAPPING_FIELD_VALUE from "@salesforce/schema/Global_Mapping__mdt.Value__c";
// import GLOBAL_MAPPING_FIELD_SECONDARY_VALUE from "@salesforce/schema/Global_Mapping__mdt.Secondary_Value__c";
// import GLOBAL_MAPPING_FIELD_PROJECT from "@salesforce/schema/Global_Mapping__mdt.Project__c";
// import GLOBAL_MAPPING_FIELD_MAP from "@salesforce/schema/Global_Mapping__mdt.Map__c";

// [values re-entered as hard-coded variables]
var OBJECT_GLOBAL_MAPPING = { objectApiName: "Global_Mapping__mdt" };
var GLOBAL_MAPPING_FIELD_KEY = { fieldApiName: "Key__c" };
var GLOBAL_MAPPING_FIELD_VALUE = { fieldApiName: "Value__c" };
var GLOBAL_MAPPING_FIELD_SECONDARY_VALUE = {
  fieldApiName: "Secondary_Value__c"
};
var GLOBAL_MAPPING_FIELD_PROJECT = { fieldApiName: "Project__c" };
var GLOBAL_MAPPING_FIELD_MAP = { fieldApiName: "Map__c" };

Note: I kept the variables as objects rather than text values as the rest of my code had been written around them functioning as such.

You must log in to answer this question.

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