8

Wondering if anyone has actually tried Metadata namespace. I have tried the following code in anonymous block in my sandbox:

Metadata.layout attachmentLayout =  new Metadata.layout();
List<String> layoutList = new List<String>{'Account-Account Layout.layout'};

List<Metadata.Metadata> components = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, layoutList);
attachmentLayout = (Metadata.layout)components.get(0);

List<Metadata.RelatedListItem> relatedLists = attachmentLayout.relatedLists;

However, this doesn't work. I am getting index out of bound exception. And the reason, of course is it failed to retrieve the account layout. Anyone knows how to fix this?

12

You don't include the "extension", but instead specify it exactly as you would in package.xml:

Metadata.layout attachmentLayout =  new Metadata.layout();
List<String> layoutList = new List<String>{'Account-Account Layout'};

List<Metadata.Metadata> components = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, layoutList);
attachmentLayout = (Metadata.layout)components.get(0);

List<Metadata.RelatedListItem> relatedLists = attachmentLayout.relatedLists;

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.