8

Here's the situation:

  • We have a Lightning App that reads from a Custom Metadata Type to populate a settings/configuration page.
  • Then you can edit the page and click save and that will create a Metadata.CustomMetadata object with containing details (such as fullName and Label, along with the configuration fields) which it then sends to Metadata.Operations.enqueueDeployment.

This all works perfectly in an unmanaged environment (Both namespaced and not). Once it's put into a managed package though, the behavior becomes strange. Instead of updating the record with the package's namespace, it instead makes a new record without any namespace (or with the namespace of the local org if ther is one).

So our product is looking at the namespaced record for it's configurations. I am able to manually edit the namespaced one (It's not protected, either the object or the record) but whenever the app tries to update it, it makes a new record. Second and third updates change this newly created record as well (it doesn't always make new records).

The question here is: How do I assign a namespace to the Metadata object records. We tried NameSpace__value as the MasterLabel and that just saved all in one string, making NameSpace__value the MasterLabel. We tried writing directly to the NamespacePrefix field and it responded with a "no such field" error. We got the same error when trying to write to DeveloperName.

I'm not including code here but it's as simple as could be, because it works fine in all non-packaged tests, I just need to know how to assign a namespace to the Custom Metadata Type record.

Thank you for your time an assistance in this.

  • Did you add the CustomMetadata to the managed package? – Itai Shmida Sep 17 '17 at 5:01
3

The app needs to be using the full, qualified name of the record. If both the type and the particular record are in NameSpace, you need:

cm.fullName = 'NameSpace__type.NameSpace__record'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.