
If you are working with templates and template folders, you might have run into challenges around displaying folder names for templates in the personal and public folders.
The API does not return folder name for Personal or Public folders in the API. The personal folder is represented by the user id and the public folder is represented by the org id.
Use the Ajax 9.0 toolkit for the template folders, do a query for templates and retrieve the templates and folder names.
In this example I am only retrieving active templates, ordering by folderID and limiting my result to 30 records
<html>
<head>
<script src="/soap/ajax/9.0/connection.js" type="text/javascript"></script>
<script>
function setupPage() {
sforce.connection.query("Select Id, Name, Subject, TemplateType, FolderId, Folder.Name From EmailTemplate Where IsActive = true order by FolderId limit 30", layoutResults);
}
The query returns the queryResults and calls the layoutResults function below.
The output variable is populated with table information for formatting.
Start the for loop for parsing through the resultset.
function layoutResults(queryResult) {
if (queryResult.size > 0) {
var output = "";
output = "<table><tr><th>ID</th><th>Template Name</th><th>Template Subject</th><th>Template Type</th><th>Folder Name</th></tr>";
var records = queryResult.getArray('records');
for (var i=0;i<records.length;i++) {
var Template= records[i];
var fname ="";
Looping through the resultset, checking if it is a personal, public or regular folder.
if (Template.FolderId.substr(0,3) == '005')
{ fname ='Personal Folder'; }
else if (Template.FolderId.substr(0,3) == '00D')
{ fname ='Public Folder'; }
else
{ fname = Template.Folder.Name; }
output += "<tr><td>" + Template.Id + " </td><td> " + Template.Name + " </td><td> " + Template.Subject + " </td><td> " + Template.TemplateType + " </td><td> " + fname + "</td></tr>";
}
output += "</table>";
document.getElementById("output").innerHTML = output;
} else {
document.getElementById("output").innerHTML = "No Folders Found.";
}
}
</script>
</head>
<body>
<body onload="setupPage()">
<div id="output"></div>
</body>
</html>