• Matt110
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

thanks in advance,. am new to sfdc dev.. please help me asap. my current code coverage is 34%

 

global class ShippedDailyEmail implements Schedulable {

List<OrderLine__c> olList = new List<OrderLine__c>();
list<order__c>orderlist=new list<order__c>();
set<id>orderid= new set<id>();
set<id> orderset=new set<id>();
global void execute (SchedulableContext SC) {
    sendEmail();
}

public void sendEmail() {
    List<Messaging.SingleEmailMessage>  myEmails = new List<Messaging.SingleEmailMessage>();
    dateTime todaysDate = system.now();   
    dateTime yesterdaysDate = todaysDate.addDays(-1);
    //system.debug('yesterday*****'+yesterdaysDate );
    system.debug('today*********'+todaysDate);
    //datetime yesterdaysDate = todaysDate.addMinutes(-5);
    system.debug('yesterday*****'+yesterdaysDate );  
   
     for (orderline__c ol: [select Name, SerialNo__c, order__r.id , order__r.requestor_email__c, order__r.requestor__c from orderline__c
                                where Shipped_Email_Sent__c = False and Actual_Ship_DateTime__c > :yesterdaysDate
                                and Actual_Ship_DateTime__c <:todaysDate])
        { 
            //add the orderline to the List
            olList.add(ol);
            orderid.add(ol.order__c);
            System.debug('Order with Shipment: ' + olList);
        }  
    
    System.debug('Order List: ' + olList.size());
    //query the list of orders and related details given the orderline list
   
   // List<orderline__c> orderList = new List<orderline__c>();
   /*
     if (olList.size()>0) {
        System.debug('Order List has records: ' + olList.size());
        orderList = [select order__r.id , order__r.requestor_email__c, order__r.requestor__c 
                     from orderline__c  
                     where Name in :olList];
    } else {
        System.debug('Order List is null');
        orderList = null;
    }  
    */
    orderlist=[select id,requestor__c from order__c where id in :orderid];                                    
    if (orderlist!= null) {
        for (order__c o: orderlist) {
        myEmails.clear();
        system.debug('count***********'+o.id);
                //build the email for each Order
               
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                // select the template
                mail.setTemplateId(System.label.DailyShippedEmailTemplate);
               
                // set the object ID the email is about
                mail.setwhatid(o.id);
                System.debug('Order id =' + o.id);
               
                // set the receipient to the correct contact
                mail.setTargetObjectId(o.requestor__c);
                //mail.setTargetObjectId('003V000000B0XIh');
               
                // set the reply-to address
                //mail.setReplyTo(System.label.ReplyToAddress);
                mail.setOrgWideEmailAddressId(System.label.ReplyToAddressID);
                //mail.setSenderDisplayName(System.label.SenderDisplayName);
                           
                // populate the CCList from the custom label
                    
                String CCList = System.label.EmailCCList;
                String[] toCC = new String[] {};
                toCC = CCList.split(',');
                mail.setCCAddresses(toCC);
              
                mail.SaveAsActivity = false;
                myEmails.add(mail);        
     
           
            try {      
                // send the emails
                Messaging.sendEmail(myEmails);
                orderset.add(o.id);
                      } catch (DMLException e) {
                System.debug('Error sending email - Error: ' + e.getDMLMessage(0));
                return;
            } catch (exception e1) {
                System.debug('Error sending email - Error: ' + e1.getMessage());
                return;
            }  
        }
       for(orderline__c o :[select id from orderline__c where order__c in:orderset and Shipped_Email_Sent__c = False and Actual_Ship_DateTime__c > :yesterdaysDate
                                and Actual_Ship_DateTime__c <:todaysDate]) 
       {
             o.Shipped_Email_Sent__c = True;
             update o;          
       }
    }
    }

  @IsTest(SeeAllData=true) public static void testShippedDailyEmail() {
           
    ShippedDailyEmail controller = new ShippedDailyEmail();
    controller.sendEmail();
   
  }
}

 

 

thanks in advance,. am new to sfdc dev.. please help me asap. my current code coverage is 34%

 

global class ShippedDailyEmail implements Schedulable {

List<OrderLine__c> olList = new List<OrderLine__c>();
list<order__c>orderlist=new list<order__c>();
set<id>orderid= new set<id>();
set<id> orderset=new set<id>();
global void execute (SchedulableContext SC) {
    sendEmail();
}

public void sendEmail() {
    List<Messaging.SingleEmailMessage>  myEmails = new List<Messaging.SingleEmailMessage>();
    dateTime todaysDate = system.now();   
    dateTime yesterdaysDate = todaysDate.addDays(-1);
    //system.debug('yesterday*****'+yesterdaysDate );
    system.debug('today*********'+todaysDate);
    //datetime yesterdaysDate = todaysDate.addMinutes(-5);
    system.debug('yesterday*****'+yesterdaysDate );  
   
     for (orderline__c ol: [select Name, SerialNo__c, order__r.id , order__r.requestor_email__c, order__r.requestor__c from orderline__c
                                where Shipped_Email_Sent__c = False and Actual_Ship_DateTime__c > :yesterdaysDate
                                and Actual_Ship_DateTime__c <:todaysDate])
        { 
            //add the orderline to the List
            olList.add(ol);
            orderid.add(ol.order__c);
            System.debug('Order with Shipment: ' + olList);
        }  
    
    System.debug('Order List: ' + olList.size());
    //query the list of orders and related details given the orderline list
   
   // List<orderline__c> orderList = new List<orderline__c>();
   /*
     if (olList.size()>0) {
        System.debug('Order List has records: ' + olList.size());
        orderList = [select order__r.id , order__r.requestor_email__c, order__r.requestor__c 
                     from orderline__c  
                     where Name in :olList];
    } else {
        System.debug('Order List is null');
        orderList = null;
    }  
    */
    orderlist=[select id,requestor__c from order__c where id in :orderid];                                    
    if (orderlist!= null) {
        for (order__c o: orderlist) {
        myEmails.clear();
        system.debug('count***********'+o.id);
                //build the email for each Order
               
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                // select the template
                mail.setTemplateId(System.label.DailyShippedEmailTemplate);
               
                // set the object ID the email is about
                mail.setwhatid(o.id);
                System.debug('Order id =' + o.id);
               
                // set the receipient to the correct contact
                mail.setTargetObjectId(o.requestor__c);
                //mail.setTargetObjectId('003V000000B0XIh');
               
                // set the reply-to address
                //mail.setReplyTo(System.label.ReplyToAddress);
                mail.setOrgWideEmailAddressId(System.label.ReplyToAddressID);
                //mail.setSenderDisplayName(System.label.SenderDisplayName);
                           
                // populate the CCList from the custom label
                    
                String CCList = System.label.EmailCCList;
                String[] toCC = new String[] {};
                toCC = CCList.split(',');
                mail.setCCAddresses(toCC);
              
                mail.SaveAsActivity = false;
                myEmails.add(mail);        
     
           
            try {      
                // send the emails
                Messaging.sendEmail(myEmails);
                orderset.add(o.id);
                      } catch (DMLException e) {
                System.debug('Error sending email - Error: ' + e.getDMLMessage(0));
                return;
            } catch (exception e1) {
                System.debug('Error sending email - Error: ' + e1.getMessage());
                return;
            }  
        }
       for(orderline__c o :[select id from orderline__c where order__c in:orderset and Shipped_Email_Sent__c = False and Actual_Ship_DateTime__c > :yesterdaysDate
                                and Actual_Ship_DateTime__c <:todaysDate]) 
       {
             o.Shipped_Email_Sent__c = True;
             update o;          
       }
    }
    }

  @IsTest(SeeAllData=true) public static void testShippedDailyEmail() {
           
    ShippedDailyEmail controller = new ShippedDailyEmail();
    controller.sendEmail();
   
  }
}