2

I am trying to get compact layouts using metatadataapi. I am using https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataServiceExamples.cls this repo to get Compact Layouts.

I have written a following code to get compact layout.

MetadataService.MetadataPort metadata = MetadataService.createService();
MetadataService.CompactLayout cl = (MetadataService.CompactLayout) metadata.readMetadata('CompactLayout', new String[] { 'Contact-APINameForCompactLayout' }).getRecords()[0];
system.debug(cl);

But in response I am getting following response

CompactLayout:[Metadata.fullName=null, apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), field_order_type_info=(fullName, fields, label), fields=null, fields_type_info=(fields, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), fullName=null, fullName_type_info=(fullName, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), label=null, label_type_info=(label, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), type=CompactLayout, type_att_info=(xsi:type)]

I have tried different name combination for in

new String[] { 'Contact-APINameForCompactLayout' }

I have tried

  • ObjectName-APINameForCompactLayout
  • ObjectName.APINameForCompactLayout
  • ObjectName.LabelForCompactLayout
  • ObjectName-LabelForCompactLayout
  • ObjectName-recordTypeName
  • ObjectName.recordTypeName

But nothing in working.

I also looked into metadata namespace that works for apex natively for metadata operations. Is there an apex function that replicates the Describe Layouts Rest Api call But it only works for Layouts not compactLayouts.

What am I missing here?How I can get compactLayouts using Metadata API?

2
  • Have you tried just passing in "ObjectName"? Commented Dec 26, 2019 at 16:17
  • yes I have tried that also Commented Dec 26, 2019 at 16:35

1 Answer 1

0

For CompactLayout fullName is ObjectApiName.CompactLayoutApiName. When I try below code it returns the correct response.

MetadataService.CompactLayout cl = (MetadataService.CompactLayout) metadata.readMetadata('CompactLayout', new String[] { 'Contact.QuickStartLayout' }).getRecords()[0];

And response is:

23:08:20:441 USER_DEBUG [7]|DEBUG|CompactLayout:[Metadata.fullName=null, apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), field_order_type_info=(fullName, fields, label), fields=(Name, Title, AccountId, Phone, MobilePhone, Email, OwnerId), fields_type_info=(fields, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), fullName=Contact.QuickStartLayout, fullName_type_info=(fullName, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), label=Quick Start Layout, label_type_info=(label, htt

You can check and verify the correcy fullName from workbench by going to Info -> Metadata Types & Components and then selecting CompactLayout. Under Components you can see your CompactLayout's information.

You must log in to answer this question.

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