certinia / apex-mdapi

Apex Wrapper for the Salesforce Metadata API
BSD 3-Clause "New" or "Revised" License
689 stars 976 forks source link

Can anyone suggest on how to read the flexipage? #301

Open yogee-areya opened 10 months ago

awalia123 commented 10 months ago

Can you please provide clarity on what you are trying to do? and the code base?

paulliu-github commented 9 months ago

@yogee-areya try the code below. If you would like to run the code in the latest API version, please read my article on LinkedIn.

MetadataService.MetadataPort service = new MetadataService.MetadataPort(); service.SessionHeader = new MetadataService.SessionHeader_element(); service.SessionHeader.sessionId = UserInfo.getSessionId(); service.timeout_x = 120000; List queries = new List();
MetadataService.ListMetadataQuery queryFlexiPage = new MetadataService.ListMetadataQuery(); queryFlexiPage.type_x = 'FlexiPage'; queries.add(queryFlexiPage);
MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 42); if (fileProperties != null) { for (MetadataService.FileProperties fileProperty : fileProperties) {
String fullName = EncodingUtil.urlDecode(fileProperty.fullName,'UTF-8'); // Read the FlexiPage MetadataService.FlexiPage flexipage = (MetadataService.FlexiPage) service.readMetadata('FlexiPage', new String[] { fullName }).getRecords()[0]; system.debug('fullName = ' + fullName); } }

yogee-areya commented 9 months ago

@paulliu-github Thank you so much for this code piece. Now i'm able to read the Metadata of Flexipages and the blog post really helps.

jaelee125 commented 9 months ago

@paulliu-github How can you go about getting all the component/item instances for the flexipage? It looks like the actual flexi page returned just has null value for flexiPageRegions

paulliu-github commented 9 months ago

@jaelee125 try this... system.debug('flexipage = ' + flexipage.flexiPageRegions[0].iteminstances[0]);

jaelee125 commented 9 months ago

@paulliu-github That line errors out because flexipage.flexiPageRegions is null

paulliu-github commented 9 months ago

@jaelee125 I don't know why it happened, have you tried to run the same code in a different org?