You need to sign in to do that
Don't have an account?
3 Creeks
Getting object names to use for Metadata.Operations.retrieve
Working with the Metadata Class introduced with ver 40, is there a way to dynamically build a list of Object names to be used in Metadata.Operations.retrieve? The full names formatted in the way that Metadata.Operations.retrieve wants them are not found in the results of a Schema.getGlobalDescribe() so I am wondering if there is some where else to get this.
A use case would be displaying a list object names to the user of the objects that a custom button can be added to.
Thanks
A use case would be displaying a list object names to the user of the objects that a custom button can be added to.
Thanks
Could you try the code below as an anonymous code first?
https://help.salesforce.com/articleView?id=code_dev_console_execute_anonymous.htm&type=0
I think it is the shorter solution that could work for your problem.
Pattern MyPattern = Pattern.compile('(?m)"name":"(.+?)"');
Pattern MyPattern = Pattern.compile('(?m)"label":"(.+?)"'); // for the labels
I don't parse the JSON response because I got an error during this parsing that you could also have.
You could get an error during the first launch of the code because a Remote Site is missing. The error message is clear and gives the "how to" for solving the problem (menu and end point).
Regards
Since the Metadata class was just introduced in Summer 2017, perhaps there is no way to get this info real clean and it is going to take something similar to what you suggest.
There is a misunderstanding because you want the layout names and not the metadata types names (__mdt)
You never wrote that your problem was the layout names for the Schema.getGlobalDescribe().
You can parse the JSON or get all these informations:
{"activateable":false,"createable":false,"custom":true,"customSetting":false,
"deletable":false,"deprecatedAndHidden":false,"feedEnabled":false,"hasSubtypes":false,
"isSubtype":false,"keyPrefix":"m00",
"label":"MyMetadataTest",
"labelPlural":"MyMetadataTests",
"layoutable":true,"mergeable":false,
"mruEnabled":true,
"name":"MyMetadataTest__mdt",
"queryable":true,"replicateable":false,
"retrieveable":true,"searchable":false,"triggerable":false,"undeletable":false,"updateable":false,
"urls":{"rowTemplate":"/services/data/v40.0/sobjects/MyMetadataTest__mdt/{ID}",
"defaultValues":"/services/data/v40.0/sobjects/MyMetadataTest__mdt/defaultValues?recordTypeId&fields",
"describe":"/services/data/v40.0/sobjects/MyMetadataTest__mdt/describe",
"layouts":"/services/data/v40.0/sobjects/MyMetadataTest__mdt/describe/layouts",
"sobject":"/services/data/v40.0/sobjects/MyMetadataTest__mdt"}},
You want to get the layouts so you need to a second call with /services/data/v40.0/sobjects/MyMetadataTest__mdt/describe/layouts
and then you have to parse the result (JSON / regular expression ).
Pattern MyPatternLayouts = Pattern.compile('(?m)"layouts":"(.+?)"');
I spent a lot of time for solving this problem of layout names for the Schema.getGlobalDescribe() in another way (but quite similar for the principle).
It is tricky but I solved also this complicated problem for my own tool I will publish soon based on the Metadata Class introduced with ver 40.
I spent a lot of time for getting a maximum of informations from this new Metadata Class.
Regards