2

I am trying to fetch an existing Page Layout using the Java client for the Metadata API, in order to update it.

However, I don't think I can properly fetch it, as it is NULL.

Here is my code:

    ReadResult readMetadataResult1 = metadataConnection.readMetadata("Layout", new String[] { "bpgdev__test__c-testLayout" });
    ReadResult readMetadataResult2 = metadataConnection.readMetadata("Layout", new String[] { "test__c-testLayout" });

    System.out.println(readMetadataResult1.getRecords().length);//prints 1
    System.out.println(readMetadataResult2.getRecords().length);//prints 1

    Layout layout1 = (Layout)readMetadataResult1.getRecords()[0];//layout1 is NULL
    Layout layout2 = (Layout)readMetadataResult2.getRecords()[0];//layout2 is NULL

And my page layout is definitely returned by a listMetadata call. Here is my code for that:

    ListMetadataQuery query = new ListMetadataQuery();
    query.setType("Layout");
    FileProperties []fileProperties = metadataConnection.listMetadata(new ListMetadataQuery[]{query}, 42.0);
    for(FileProperties prop: fileProperties){
        System.out.println(prop.getFullName());//outputs test__c-testLayout amongst others
    }

Can anyone give me any ideas as to what I am missing?

I have tried both with and without namespace, none working.

1 Answer 1

0

I think the problem you're having is the Object Type = "Layout" (string).

What you want to retrieve is the (string) fullName = "bpgdev__test__c-testLayout".

It's either that or you want to to retrieve the (string) fullName_type_info.

I believe it should be one or the other.

2
  • I am sorry I don't think I understand you .. can you please explain a bit more? May 2, 2018 at 6:56
  • When I look at the MDAPI section for Layout, it shows String type = 'Layout';, then there's String fullname; and also String[] fullName_type_info = new String[]{'fullName','http://soap.sforce.com/2006/04/metadata',null,'0','1','false'};. That's what the MDAPI is using to return what you're also looking for. See metadataservice.cls in github.com/financialforcedev/apex-mdapi for more.
    – crmprogdev
    May 2, 2018 at 12:38

You must log in to answer this question.

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