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
p sonwanep sonwane 

Not recieving email on my account.

Hello Team , 
I have implemented email send functuonality using lightning email template . my code is working fine . i checked in log also everything is correct but i am not getting email . below is my code .


public class ApplicationService{
    
    public static void createApplications(){
        List<Application__c> appList2= new List<Application__c>();
        List<Application__c> appList=[Select Id, Status__c,Contact__r.Email,Contact__r.Id, Application_Status__c 
                                          from Application__c where Status__c = 'Publish in Progress' 
                                          AND(Application_Status__c ='Admitted' or Application_Status__c ='Not Admitted')];
                                          
        EmailTemplate TemplateId= [SELECT Id, Body FROM EmailTemplate WHERE Name = 'Learner_Approved_Template'];
        for(Application__c app:appList){
            List<String> toAddressList=new List<String>();
            toAddressList.add(app.Contact__r.Email);
                        System.debug('**Contact Email:'+app.Contact__r.Email);
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(toAddressList);
            email.setTargetObjectId(app.Contact__r.id); //contact.id
            email.setWhatId(app.Id);
            email.setSaveAsActivity(false);
            email.setUseSignature(false);
            
            if(app.Application_Status__c =='Admitted'){
                email.setTemplateId(templateId.Id);
                email.setHTMLBody(templateId.Body);
            }
            else if(app.Application_Status__c =='Not Admitted'){
                //EmailTemplate TemplateId= [SELECT Id, Body FROM EmailTemplate WHERE Name = 'LXP_Learner_Rejection_Template'];
                email.setTemplateId(templateId.Id);
                email.setHTMLBody(templateId.Body);
            }
            
            Messaging.SendEmailResult[] sendResults = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ email });
            System.debug('sendResults**'+sendResults);
            if(sendResults[0].isSuccess()) {
                app.Status__c ='Published';
                system.debug('Email sent');
                appList2.add(app);
            } 
            else{
                system.debug('Email not send');} 
        }
        if(appList2.size()>0){
            update appList2;
        }
    }
}
SubratSubrat (Salesforce Developers) 
Hello Pooja ,

Can you check the Email Delieveribilirty  option under setup .
Reference Link -> (https://help.salesforce.com/s/articleView?id=sf.data_sandbox_email_deliverability.htm&type=5)

If this helps , please mark this as Best Answer.
Thank you.
p sonwanep sonwane
@subrat , i have alredy checked Delieveribilirty and its default set to all mail but still not getting anyn mails 
SubratSubrat (Salesforce Developers) 
Hello pooja ,

Please refer this troubleshooting steps for your requirement and let me know further -> https://help.salesforce.com/s/articleView?id=000386389&type=1 (https://help.salesforce.com/s/articleView?id=000386389&type=1)

Thank you.