• saud shrumtech
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
How do i avoid the Email limit that is 10-15 for a day ?

trigger LeaveUpdatetrigger on Leave__c (after update,before delete) {
    
    if(trigger.isInsert || trigger.isUpdate){
        for(Leave__c lv : trigger.new){
            Leave__c lev = [Select Name,EmployeeName__r.Name from Leave__c where EmployeeName__c =:lv.EmployeeName__c limit 1];
            EmailTemplate et = [SELECT Id,Subject,HtmlValue, Body FROM EmailTemplate WHERE DeveloperName =:'Update_to_Hr_on_Leave_modification'];
             system.debug('--EmailTemplate--'+et);
            //String subject = 'TEST';
            String body = et.HtmlValue;
            body = body.replace('{!Leave__c.EmployeeName__c}',lev.EmployeeName__r.Name);
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.toAddresses = new String[] { 'saudsyed20@gmail.com' };
                mail.setSubject(et.subject);
            mail.setHtmlBody(body);
            
            mail.setplainTextBody(et.body);
            // mail.setTargetObjectIds(lv.id);
            mail.setTemplateId('00X2v000001H9oK'); //Id of the Email Template
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
    }
   // if(trigger.isdelete)
     if(Trigger.isBefore || trigger.isdelete){
        for(Leave__c lv : trigger.old)
        {
            Leave__c lev = [Select Name,EmployeeName__r.Name from Leave__c where EmployeeName__c =:lv.EmployeeName__c limit 1];
            
            EmailTemplate et = [SELECT Id,Subject,HtmlValue, Body FROM EmailTemplate WHERE DeveloperName =:'Update_to_HR_on_Leave_deletion'];
            //system.debug('--EmailTemplate--'+et);
            //String subject = 'TEST';
            String body1 = 'TEST';
            String body =et.HtmlValue;
            body = body.replace('{!Leave__c.EmployeeName__c}',lev.EmployeeName__r.Name);
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.toAddresses = new String[] { 'saudsyed20@gmail.com' };
                mail.setSubject(et.subject);
            mail.setHtmlBody(body);
            mail.setplainTextBody(et.body);
            // mail.setTargetObjectIds(lv.id);
            //mail.setTemplateId('00X2v000001H9oe'); //Id of the Email Template
            mail.setTemplateId('00X2v000001H9oe');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }                    
    }
}
Having two objects ,parent object as Employee and field is employee name and another object is Leave where employee name is look up
trigger LeaveUpdatetrigger on Leave__c (after update,after delete) {
   
    if(trigger.isInsert || trigger.isUpdate){
        for(Leave__c lv : trigger.new){
         EmailTemplate et = [SELECT Id,Subject,HtmlValue, Body FROM EmailTemplate WHERE DeveloperName =:'Update_to_Hr_on_Leave_modification'];
        system.debug('--EmailTemplate--'+et);
        //String subject = 'TEST';
        //String body ='THIS IS ME';
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.toAddresses = new String[] { 'xyz@gmail.com' };
            mail.setSubject(et.subject);
            mail.setHtmlBody(et.HtmlValue);
           
        mail.setplainTextBody(et.body);
       // mail.setTargetObjectIds(lv.id);
        mail.setTemplateId('00X2v000001H9oK'); //Id of the Email Template
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
    }
    if(trigger.isdelete){
        for(Leave__c lv : trigger.old){
         EmailTemplate et = [SELECT Id,Subject,HtmlValue, Body FROM EmailTemplate WHERE DeveloperName =:'Update_to_HR_on_Leave_deletion'];
        system.debug('--EmailTemplate--'+et);
        //String subject = 'TEST';
        //String body ='THIS IS ME';
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.toAddresses = new String[] { 'xyz@gmail.com' };
            mail.setSubject(et.subject);
            mail.setHtmlBody(et.HtmlValue);
           
        mail.setplainTextBody(et.body);
       // mail.setTargetObjectIds(lv.id);
        mail.setTemplateId('00X2v000001H9oe'); //Id of the Email Template
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }                    
    }
}
 
Having two objects ,parent object as Employee and field is employee name and another object is Leave where employee name is look up
trigger LeaveUpdatetrigger on Leave__c (after update,after delete) {
   
    if(trigger.isInsert || trigger.isUpdate){
        for(Leave__c lv : trigger.new){
         EmailTemplate et = [SELECT Id,Subject,HtmlValue, Body FROM EmailTemplate WHERE DeveloperName =:'Update_to_Hr_on_Leave_modification'];
        system.debug('--EmailTemplate--'+et);
        //String subject = 'TEST';
        //String body ='THIS IS ME';
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.toAddresses = new String[] { 'xyz@gmail.com' };
            mail.setSubject(et.subject);
            mail.setHtmlBody(et.HtmlValue);
           
        mail.setplainTextBody(et.body);
       // mail.setTargetObjectIds(lv.id);
        mail.setTemplateId('00X2v000001H9oK'); //Id of the Email Template
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
    }
    if(trigger.isdelete){
        for(Leave__c lv : trigger.old){
         EmailTemplate et = [SELECT Id,Subject,HtmlValue, Body FROM EmailTemplate WHERE DeveloperName =:'Update_to_HR_on_Leave_deletion'];
        system.debug('--EmailTemplate--'+et);
        //String subject = 'TEST';
        //String body ='THIS IS ME';
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.toAddresses = new String[] { 'xyz@gmail.com' };
            mail.setSubject(et.subject);
            mail.setHtmlBody(et.HtmlValue);
           
        mail.setplainTextBody(et.body);
       // mail.setTargetObjectIds(lv.id);
        mail.setTemplateId('00X2v000001H9oe'); //Id of the Email Template
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }                    
    }
}