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
sfdclivesfdclive 

Email template query

public id emailtemplateid{get;set;}
//private final ApexPages.StandardController thecontroller;
public List<SelectOption> emailtemplates {
    get {
      if (emailtemplates == null) {
       emailtemplates = new List<SelectOption>();
        emailtemplates.add(new SelectOption('00Xf0000000Hzi9','Dealer Source - TEST'));
        emailtemplates.add(new SelectOption('00Xf0000000I0MT','News Snapshot'));
      }
      return emailtemplates;
    }
    set;
  }

Hi,

i want emailtempaltes as dropdown list , here i hardcoded emailtempalte ids for dropdown. please suggest me the code with out hard coding.
Best Answer chosen by Admin (Salesforce Developers) 
zachbarkleyzachbarkley

Try:

 

public List<SelectOption> emailtemplates {
    get {
    	List <SelectOption> options= new List <SelectOption>();
    	List<EmailTemplate> ET = [SELECT Id,Name FROM EmailTemplate WHERE IsActive=true];
    	options.add(new selectOption('', '- select -' )); 
    	for(EmailTemplate R:ET){
        	options.add(new selectOption(R.Id, R.Name));
    	} 
        return options;
    }
    set;
}