Metadata.CustomMetadata class causes inspector errors

Issue #1052 resolved
Aidan Harding created an issue

I'm getting errors from the inspector when using the Metadata.CustomMetadata class in Apex. If I just take the "Deploy Metadata" example from SF docs here:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Metadata_Operations.htm#apex_class_Metadata_Operations

public class CreateMetadata{
  public void updateAndDeployMetadata() {
    // Setup custom metadata to be created in the subscriber org.
    Metadata.CustomMetadata customMetadata =  new Metadata.CustomMetadata();
    customMetadata.fullName = 'ISVNamespace__MetadataTypeName.MetadataRecordName';

    Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
    customField.field = 'customField__c';
    customField.value = 'New value';

    customMetadata.values.add(customField);

    Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
    mdContainer.addMetadata(customMetadata);

    // Setup deploy callback, MyDeployCallback implements
    // the Metadata.DeployCallback interface (code for
    // this class not shown in this example)
    MyDeployCallback callback = new MyDeployCallback();

    // Enqueue custom metadata deployment
    Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback);
  }
}

Then, the inspector thinks that:

customMetadata.fullName = 'ISVNamespace__MetadataTypeName.MetadataRecordName';

is using incompatible types. And it cannot find the definition for "add" in the following:

customMetadata.values.add(customField);

Obviously, it's not a show-stopper as I can save my work anyway, but it would be nice to have fewer red lines!

Comments (4)

  1. Scott Wells repo owner

    Sorry...let me try again. On further inspection, you're correct that this is another instance of #821. The Salesforce Tooling API that provides descriptions of system types isn't including all of the details about types from the new Metadata namespace, in particular the field data types. I'll ping Salesforce about this and see if/when they're planning to address it.

  2. Scott Wells repo owner

    Aidan, I confirmed that the issue is with Salesforce's Tooling API completions resource. It doesn't return type information for properties, and the types in the Metadata namespace are pretty much containers for properties vs. accessor methods for internal data which could include type information. Here's a sample of what you get back from the completions resource for those properties:

    Issue1052.png

    Unfortunately this is something that Salesforce is going to need to resolve because the scope of the issue is quite broad. I'll follow up with them and ask if/when they're going to take care of this.

  3. Scott Wells repo owner

    I've just reached out to a few folks who should be able to provide thoughts on how/when this omission of important type information will be resolved. If/when I hear anything useful, I'll try to provide an update here.

  4. Log in to comment