6

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);
System.debug(layout);

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.

3
  • The example in the Metadata Operations seems to concur as they use 'ISVNamespace__TestCustomMDType.MyTestCustomMDType' Aug 9 '17 at 2:34
  • Maybe also try Aaron Slettehaugh via the Apex Metadata API success group? Aug 9 '17 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
    Aug 9 '17 at 4:16
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);
System.debug(layout);
4
  • That's the problem, it wasn't working in this situation.
    – Matt Lacey
    Oct 20 '17 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
    Oct 21 '17 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
    Oct 23 '17 at 18:25
  • I wonder if this would work for you since double prefixing works perfect for me
    – Patlatus
    Oct 24 '17 at 7:53

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.