You need to sign in to do that
Don't have an account?
Need help to add customField to list of values in customMetadata
Hello,
Can someone help me with module Metadata API, unit Build Admin Tools for Automated Configuration Changes?
The error I'm getting is:
Line 12: Method does not exist or incorrect signature; void add(Metadata.CustomMetadataValue) from the type List
Below is my code:
public class MetadataExample {
public void updateMetadata () {
Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata();
customMetadata.fullName = 'MyNamespace__MyMetadataTypeName.MyMetadataRecordName';
Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
customField.field = 'customField__c';
customField.value = 'New value';
List <Metadata.CustomMetadata> mdtlist = new List<Metadata.CustomMetadata>();
mdtlist.add(customField); // Line 12
}
}
I feel like I'm missing something very basic but I can't find any documentation specific to what I'm trying to do and the challenge is not similar (to me) to the example. Can someone please explain where I went wrong?
Can someone help me with module Metadata API, unit Build Admin Tools for Automated Configuration Changes?
The error I'm getting is:
Line 12: Method does not exist or incorrect signature; void add(Metadata.CustomMetadataValue) from the type List
Below is my code:
public class MetadataExample {
public void updateMetadata () {
Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata();
customMetadata.fullName = 'MyNamespace__MyMetadataTypeName.MyMetadataRecordName';
Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
customField.field = 'customField__c';
customField.value = 'New value';
List <Metadata.CustomMetadata> mdtlist = new List<Metadata.CustomMetadata>();
mdtlist.add(customField); // Line 12
}
}
I feel like I'm missing something very basic but I can't find any documentation specific to what I'm trying to do and the challenge is not similar (to me) to the example. Can someone please explain where I went wrong?
All Answers
Couldn't find use of the 'Metadata.Operations.enqueueDeployment' method to deploy the metadata, or assignment of the return value of the method to a variable called 'asyncResultId' of type 'Id'. Please double-check the instructions.
Here's my class:
public class MetadataExample {
public class MyCallback implements Metadata.DeployCallback {
public void handleResult(Metadata.DeployResult result,
Metadata.DeployCallbackContext context) {
if (result.status == Metadata.DeployStatus.Succeeded) {
// Deployment was successful
} else {
// Deployment was not successful
}
}
}
public void updateMetadata () {
Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata();
customMetadata.fullName = 'MyNamespace__MyMetadataTypeName.MyMetadataRecordName';
Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
customField.field = 'customField__c';
customField.value = 'New value';
customMetadata.values.add(customField);
Metadata.DeployContainer deployContainer = new Metadata.DeployContainer();
deployContainer.addMetadata(customMetadata);
MyCallback callback = new MyCallback();
Metadata.Operations.enqueueDeployment(deployContainer, callback);
Id asyncResultId = Metadata.Operations.enqueueDeployment(deployContainer, callback);}
}
Any thoughts? Thanks!!
no callback is required instead use null as 2nd parameter of the function as instructed
Thanks for your answer....
This Challenge has a bit of a bad reputation, it doesn't even let user pass the challenge if you have even a single line break between some statements.
For me this line of code worked
But the code on block with a line break, challenge fails and says you are missing either customField.field or customField.value I think this challenge needs to be updated to check for content and not the exact code.