Skip to main content
Har par a posé une question dans #Customer Service
HI all,

 

 I have a requirement to send an email to customer by selecting an template.

 

problem in coding ..I am able to send an email without template but the requirement is with template.How can i code to send an email to have an option to select a template before sending.

 

Here is the code i tried.

 

          try  

 

          {

 

            Set<ID> FolderIds = new Set<ID>();

 

            List<Folder> Folders = [Select Id, Name From Folder Where developername='templatename'];

 

            for(Folder F : Folders)

 

{

 

FolderIds.add(F.Id); }

 

            

 

            List<EmailTemplate> objTemplate = [Select Id,body,markup,HtmlValue From EmailTemplate Where name=:lstEmlApproved[0].Select_Template__c And Folder.Id IN :FolderIds limit 1];

 

            string htmlbody;

 

            string strSubject;

 

            htmlbody=objTemplate[0].HtmlValue;

 

            //strSubject=objTemplate.Subject;

 

             string subject=lstEmlApproved[0].Subject__c+'  '+lstEmlApproved[0].Case__r.Case_Thread_Id__c;

 

            

 

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

 

             mail.setTargetObjectId(lstEmlApproved[0].Case__r.contactid);  

 

             mail.setWhatId(lstEmlApproved[0].Case__c);     

 

             mail.setSubject(subject);

 

             mail.setSenderDisplayName('xxx');   

 

            mail.replyTo = 'xxx';

 

            

 

             if(objTemplate.size()>0)

 

                 mail.setHtmlBody(lstEmlApproved[0].Description__c+ '<br>'+objTemplate[0].body);

 

             else

 

                  mail.setHtmlBody(lstEmlApproved[0].Description__c);

 

             //mail.useSignature = true;      

 

             //mail.setToAddresses(toaddress);

 

             Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

             lstEmlApproved[0].Email_Sent__c='Yes';

 

             update lstEmlApproved;

 

             

 

          }   

 

          catch(Exception ex)

 

          {

 

              system.debug('Exception occured in SendEmailAfterApp class method sendEmailButton'+ex);

 

          }

 

         

 

        }      

 

         return true; 
1 réponse
0/9000