+ Start a Discussion
Raghvendra Singh 22Raghvendra Singh 22 

Fetch the Email template and folder and show in dropdown in Lightning Component

Hi Guys,

How to achive this:  Fetch the Email template and show in dropdown in Lightning Component

Thanks,
Raghu
Best Answer chosen by Raghvendra Singh 22
Raj VakatiRaj Vakati
Here is the code
 
public class EmailController {
    @AuraEnabled 
    public static List<EmailTemplate> getEmailTemplate(){
        return [SELECT Id,Body,DeveloperName FROM EmailTemplate];
    }
}
 
<aura:component controller="EmailController">
    
    <aura:attribute name="options" type="List" default=""/>
    
    
    <aura:handler name="init" value="this" action="{!c.doInit}"/>
    
    
    <lightning:combobox name="Email Templates" label="Email Templates" value="Email Templates" placeholder="Select Email Templates" 
                        options="{! v.options }" onchange="{! c.handleChange }"/>
    
    
    
</aura:component>
 
({
    doInit : function(component, event, helper) {
        var action = component.get("c.getEmailTemplate");
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                let resp =response.getReturnValue() ;
                let lables= [] ; 
                resp.forEach(function(key) {
                    lables.push({"label":key.DeveloperName ,"value":key.DeveloperName});
                });
                component.set("v.options", lables);
                //   cmp.set("v.contactList", response.getReturnValue());
            }
            
        })
        
        $A.enqueueAction(action);
        
    },
    
    handleChange: function(component, event, helper){
        
        
    }
    
})



 

All Answers

Raj VakatiRaj Vakati
Here is the code
 
public class EmailController {
    @AuraEnabled 
    public static List<EmailTemplate> getEmailTemplate(){
        return [SELECT Id,Body,DeveloperName FROM EmailTemplate];
    }
}
 
<aura:component controller="EmailController">
    
    <aura:attribute name="options" type="List" default=""/>
    
    
    <aura:handler name="init" value="this" action="{!c.doInit}"/>
    
    
    <lightning:combobox name="Email Templates" label="Email Templates" value="Email Templates" placeholder="Select Email Templates" 
                        options="{! v.options }" onchange="{! c.handleChange }"/>
    
    
    
</aura:component>
 
({
    doInit : function(component, event, helper) {
        var action = component.get("c.getEmailTemplate");
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                let resp =response.getReturnValue() ;
                let lables= [] ; 
                resp.forEach(function(key) {
                    lables.push({"label":key.DeveloperName ,"value":key.DeveloperName});
                });
                component.set("v.options", lables);
                //   cmp.set("v.contactList", response.getReturnValue());
            }
            
        })
        
        $A.enqueueAction(action);
        
    },
    
    handleChange: function(component, event, helper){
        
        
    }
    
})



 
This was selected as the best answer
Raghvendra Singh 22Raghvendra Singh 22
Hi Raj,
Thanks for your reply.
But i am getting this error:

This page has an error. You might just need to refresh it. Unable to find 'doinit' on 'compound://c.SendEmail'. Failing descriptor: {markup://c:SendEmail}
Raj VakatiRaj Vakati
Did you add all the controller code ? it should work.. Please share the code to see the issue 
Raj VakatiRaj Vakati
Please add the apex class and component and controller 
Raghvendra Singh 22Raghvendra Singh 22
Thanks its working perfectly ... there is some error in init event.  
One more requirment i have .. could you please tell me : how to get email template inside this folder:
whenever i click any folder it should show all email template in checkbox so that user can click and use that email template


Thank you Raj
Raj VakatiRaj Vakati
let me write the code 
Raghvendra Singh 22Raghvendra Singh 22
Thank you Raj .i am also writing
 
Raghvendra Singh 22Raghvendra Singh 22
Hi Raj,
did you find the logic 
Thanks
Marek HarmsMarek Harms
Hi guys!
I found this incredible post and would like to thank you for sharing this approach!
I have included the code into the flow and I can see all the templates in a long list, no folder structure.
Is there something I have to be aware?
In addition to Raghvendra's requirement, how would the last step, selecting the email template and actually using/sending the mail look like.
My approach would be to using this link:

https://na15.salesforce.com//_ui/core/email/author/EmailAuthor?rtype=003&p3_lkid={!recordId}&retURL={!recordId}&p6={!SubjectLine313}&template_id=[WhatComesHere?]

EmailAuthor should be the user
{!recordId} = Case ID (email should be linked to a case)
{!SubjectLine313} = Subject line that has been defined as variable in the flow
template_id = ???

Many thanks for your support!

Cheers,
Marek