function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rajat Mahajan 48Rajat Mahajan 48 

How to retrieve all page layouts via Metadata Class???

Hi All

Can anyone please help me understand how to retrieve all page layouts for an object using metadata api

In trail head i was able to find a snippet where you can retrieve one layout, but not all together. Was not able to figure out how to retrieve all-
//Method created to retrieve / query the page layouts of an object
    public static void queryPageLayouts() {
        
        // Retrieve Account layout and section 
        List<Metadata.Metadata> layouts = 
            Metadata.Operations.retrieve(Metadata.MetadataType.Layout, 
            new List<String> {'Account-Account (Marketing) Layout'});
        
        for(Metadata.Metadata layout : layouts) {
            System.debug('The layouts in Accounts are:'+ layout.fullname);        
        }
    }

The above helps me get one layout, if i were to retrieve all layouts, how should i write my code

Thanks,
Rajat
Santosh Reddy MaddhuriSantosh Reddy Maddhuri
// this is the Login method ... please refer to Metadata Api documentation 
metadatabinding = (MetadataBindingStub)new MetadataServiceLocator().getMetadata();


// this is another method in which you call the listMetadata method
 ListMetadataQuery query = new ListMetadataQuery();
    query.setType("Layout");
    double asOfVersion = 23.0;
    // Assuming that the SOAP binding has already been established.
    FileProperties[] metadatafile = metadatabinding.listMetadata(
    new ListMetadataQuery[] {query}, asOfVersion);
    if (metadatafile != null) {
    for (FileProperties fp : metadatafile) {
       if(fp.getFullName().contains("Account")){
        System.out.println("Component fullName: " + fp.getFullName());
        System.out.println("Component type: " + fp.getType());
            }
        }

https://stackoverflow.com/questions/9949078/can-i-access-all-page-layouts-specific-to-an-object-via-the-salesforce-api