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
AmbigaRamAmbigaRam 

how to display the case number in email template?

Hi,

The following is the content of my email template, and my template name is "Case email"

"Thanks , Your case number is {!Case.CaseNumber}"


And my Apex Trigger to send the email, when the case is created.

 

trigger mailNotification on Case ( after insert) {
    contact CaseContact;
    
    for(case Cases :trigger.new){
                    //Fetch the related case contact.
                CaseContact = [SELECT Email FROM Contact WHERE Id = :Cases.ContactId];
                if (CaseContact != null && CaseContact.Email != null) {
    Messaging.SingleEmailMessage CaseNotificationmail = new Messaging.SingleEmailMessage();
    EmailTemplate template = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Name = 'Case Email '];
    CaseNotificationmail.setToAddresses(new List<String> { CaseContact.Email });
    CaseNotificationmail.setReplyTo('someone@salesforce.com');
    CaseNotificationmail.setSenderDisplayName('Salesforce Support');
    CaseNotificationmail.setTargetObjectId(CaseContact.Id);
    CaseNotificationmail.setTemplateId(template.id);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { CaseNotificationmail });
 } 
  
}

}

  after creating the case, It sends the mail, but It does nt show the case number.

 

Can anybody help for this?

 

Regards.,

Ambiga.R

Sujit NirkheSujit Nirkhe

Try it to get a Case:
CaseContact = [SELECT Id, Email FROM Contact WHERE Id = :Cases.ContactId];


Hit Kudos if u find it helpful
AmbigaRamAmbigaRam

Hi, 

 

Thanks Sujit Nirke,  but It does not work!

 

 

 

Regards

Ambiga.R