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

Metadata API, Finding the optional folder name for ListMetadataQuery

I'm attempting to query the service using the ListMetadataQuery and the ListMetadata() method for:

Documents, Email Templates, Reports, and Dashboards.


These items require a value in the ListMetadataQuery.folder value. But I'm unable to determine (via the API) the names of the folders.


When I initially call the describeMetadata(), it returns these components in the DescribeMetadataResult.metadataObjects. It also shows that these are in a folder

(DescribeMetadataObject.inFolder = true), but I cannot find a clue as to the names of the folders.


/// <summary> /// BuildMetadata queries the server for all the names of components (types) /// in the org. /// </summary> /// <returns>A Package object containing information for each type</returns> public Package BuildMetadata() { Package package = new Package(); package.version = apiVersion.ToString(); try { SortedDictionary<string, PackageTypeMembers> alltypes = new SortedDictionary<string, PackageTypeMembers>(); // Assuming that the SOAP binding has already been established. DescribeMetadataResult res = metaService.describeMetadata(apiVersion); if (res != null && res.metadataObjects.Count() > 0) { foreach (DescribeMetadataObject obj in res.metadataObjects) { if (obj.childXmlNames != null) { foreach (string name in obj.childXmlNames) { if (name != string.Empty) { PackageTypeMembers childcomponent = new PackageTypeMembers(); // = obj.xmlName + "." + name; = name; alltypes.Add(, childcomponent); } } if (!alltypes.ContainsKey(obj.xmlName)) { PackageTypeMembers parentcomponent = new PackageTypeMembers(); = obj.xmlName; alltypes.Add(, parentcomponent); } } else { if (!alltypes.ContainsKey(obj.xmlName)) { PackageTypeMembers component = new PackageTypeMembers(); = obj.xmlName; alltypes.Add(, component); } } } } package.types = alltypes.Values.ToArray(); } catch (Exception ex) { Console.WriteLine("\nFailed to describe metadata, error message was: \n" + ex.Message); throw ex; } return package; } /// <summary> /// listMetadata retrives all the members of the requested component (type) /// </summary> /// <param name="component">Name of component (Report, CustomObject, ApexClass)</param> /// <returns>A list of names of the objects of that type</returns> public List<string> listMetadata(string component) { SortedList<string, string> results = new SortedList<string, string>(); FileProperties[] lmr = null; try { string optionalFolder = ""; string comp = component; if (component.Contains(".")) { string[] path = component.Split('.'); optionalFolder = path[0]; comp = path[1]; } // <=== These are hard coded folder names, because I don't know how to // find the names of the folders to request else if (component == "Dashboard") optionalFolder = "My Personal Dashboards"; else if (component == "Document") optionalFolder = "My Personal Documents"; else if (component == "EmailTemplate") optionalFolder = "My Personal Email Templates"; else if (component == "Report") optionalFolder = "My Personal Custom Reports"; ListMetadataQuery query = new ListMetadataQuery(); query.folder = optionalFolder; query.type = comp; try { lmr = metaService.listMetadata( new ListMetadataQuery[] { query }); } catch (Exception ex) { Console.WriteLine("\nFailed to list metadata, error message was: \n" + ex.Message); } if (lmr != null) { foreach (FileProperties n in lmr) { if (!results.ContainsKey(n.fullName)) results.Add(n.fullName, n.fullName); Console.WriteLine("Component fullName: " + n.fullName); Console.WriteLine("Component type: " + n.type); } } } catch (Exception ex) { Console.WriteLine("\nFailed to list metadata, error message was: \n" + ex.Message); throw ex; } return results.Values.ToList(); }


Best Answer chosen by Admin (Salesforce Developers) 
does this help ?

All Answers

does this help ?
This was selected as the best answer

Yes, it does. Thanks Simon.

I should have searched your blog first. I already have a link to it.


So there is a ReportsFolder.

Should I assume there's a DocumentsFolder, EmailTemplatesFolder, and DashboardsFolder?



Shishir VKShishir VK


Iam trying to create reports under a specific folder in SFDC, using the MetaData API.

But when i use the ReportFolder Class or the Report class (which come as part of the MetaData  API), I don't find any options to link both (Report with ReportFolder), Kindly help its Urgent....