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
Niklas HillgrenNiklas Hillgren 

Metadata API - Layout is null

I'm working on integration with the parnter/metadata API. I'm using maven as build tool where I have a dependency to the partner/metadata api using the following package http://mvnrepository.com/artifact/com.force.api (Version 34.0.0).

I'm trying to read the Layout metadata using the following utility method:
public T readMetaDataSync(Class<T> metaDataType, String metaDataName) {
		System.out.println("Fetching metadatatype: " + metaDataType.getSimpleName() + " name: " +metaDataName);
		
		T obj = null;
	    try {
	        ReadResult readResult = sfCredentials.getMetadataConnection().readMetadata(metaDataType.getSimpleName(), new String[] { metaDataName });
	        Metadata[] mdInfo = readResult.getRecords();
	        for (Metadata md : mdInfo) {
	            if (md != null) {
	            	obj = metaDataType.cast(md);
	                
	                return obj;
	            } else {
	                System.out.println("Empty metadata.");
	            }
	        }
	    } catch (ConnectionException ce) {
	        ce.printStackTrace();
	    }
	    
	    return obj;
	}

When the method is run for com.sforce.soap.metadata.Layout.class i get the following output:

Fetching metadatatype: Layout name: Contact-Contact Layout
Empty metadata.
However if I change the metadataconnection to a different Salesforce.org it does work and the Layout metadata for Contact is not null.

If I call the same method using the parameters com.sforce.soap.metadata.Metadata.class and the string "Contact" it works for both orgs.

Does anyone have a hint/tips where i can look to figure it out?
Best Answer chosen by Niklas Hillgren
Niklas HillgrenNiklas Hillgren

I've manage to solve why it didn't work. 

I've got the layout name for the Contac-Contact layout from listmetadata function: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_listmetadata.htm

For the org that didn't work it was a namespace - however the namespace was not included in the fullname of the FileProperties[] getFullname function...

To be able to update/read the specific Layout metadata the namespace i've added the namespace manually:

Contact-Contact Layout -> Contac-namespace__Contact layout.

Cheers,
Niklas