+ Start a Discussion
JPClarkJPClark 

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(); //childcomponent.name = obj.xmlName + "." + name; childcomponent.name = name; alltypes.Add(childcomponent.name, childcomponent); } } if (!alltypes.ContainsKey(obj.xmlName)) { PackageTypeMembers parentcomponent = new PackageTypeMembers(); parentcomponent.name = obj.xmlName; alltypes.Add(parentcomponent.name, parentcomponent); } } else { if (!alltypes.ContainsKey(obj.xmlName)) { PackageTypeMembers component = new PackageTypeMembers(); component.name = obj.xmlName; alltypes.Add(component.name, 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) 
SuperfellSuperfell
does this help ? http://www.pocketsoap.com/weblog/2008/10/1826.html

All Answers

SuperfellSuperfell
does this help ? http://www.pocketsoap.com/weblog/2008/10/1826.html
This was selected as the best answer
JPClarkJPClark

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?

 

Jeff

Shishir VKShishir VK

Hi,

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....