So using the spanking new meta data in Apex you can get page layout information (at last!):

List<String> componentNameList = new List<String>{'Opportunity-Opportunity Layout'};
List<Metadata.Metadata> components = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, componentNameList);

layout = (Metadata.Layout) components.get(0);

Yes, the above code is nasty but it works. What doesn't work is getting a page layout from our managed package. Everything I can find suggests that it simply needs the standard namespace__ in front of the object:

List<String> componentNameList = new List<String>{'PRX__Transaction__c-Transaction Layout'};

But that's not returning anything and I have confirmed the layout name via MavensMate:

MavensMate screenshot showing layout name as PRX__Transaction__c-Transaction Layout

What am I missing here? The checkbox to allow packages to update metadata is checked (tried both ways) but there's nothing else I can think of to check.

  • The example in the Metadata Operations seems to concur as they use 'ISVNamespace__TestCustomMDType.MyTestCustomMDType' Commented Aug 9, 2017 at 2:34
  • Maybe also try Aaron Slettehaugh via the Apex Metadata API success group? Commented Aug 9, 2017 at 2:38
  • 1
    Yeah I might have to. I really wish they'd remove the SSO on that, you can guarantee I'll have yet another new profile by the end of the day.
    – Matt Lacey
    Commented Aug 9, 2017 at 4:16

1 Answer 1


The rules for Metadata.Operations class are the same as the rules for Metadata API, so answer from these questions worked well for me, you just need to double prefix the namespace in format <namespace>__<Object Name>-<namespace>__<Layout Name>

So this code works fine for me

List<String> componentNameList = new List<String>{'PRX__Transaction__c-PRX__Transaction Layout'};
List<Metadata.Metadata> components = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, componentNameList);

Metadata.Layout layout = (Metadata.Layout) components.get(0);
  • That's the problem, it wasn't working in this situation.
    – Matt Lacey
    Commented Oct 20, 2017 at 20:10
  • it is because you tried new List<String>{'PRX__Transaction__c-Transaction Layout'}; but most probably haven't tried new List<String>{'PRX__Transaction__c-PRX__Transaction Layout'};
    – Patlatus
    Commented Oct 21, 2017 at 14:04
  • Oh my bad, I missed that second use of the prefix. I'll give it a go and see what happens!
    – Matt Lacey
    Commented Oct 23, 2017 at 18:25
  • I wonder if this would work for you since double prefixing works perfect for me
    – Patlatus
    Commented Oct 24, 2017 at 7:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .