Reputation: 7649
Hi i created an object in which onefield is lookup to user and other field is id of email template . i have to create a visualforce page in which i have to assign different email templates to different users and then save records of custom object. can u please tell me how to get all email templates Name and id created in MyTemplates in picklist of VF page??
Upvotes: 0
Views: 4719
Reputation: 852
APEX CONTROLLER
public class TemplateSelectorController {
public String selectedTemplateId { public get; public set; }
public List<SelectOption> getMyPersonalTemplateOptions() {
List<SelectOption> options = new List<SelectOption>();
for (EmailTemplate t : [
select Id,Name
from EmailTemplate
// Each User has a 'My Personal Templates' folder
// of EmailTemplates, whose Id is the User's Id
where FolderId = :UserInfo.getUserId()
]) {
options.add(new SelectOption(t.Id,t.Name));
}
return options;
}
}
VISUALFORCE PAGE
<apex:page controller="TemplateSelectorController">
<apex:form>
<apex:selectList value="{!selectedTemplateId}">
<apex:selectOptions value="{!myPersonalTemplateOptions}"/>
</apex:selectList>
</apex:form>
</apex:page>
Upvotes: 1