• Krista Kelly
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hello, it's been requested that when our users hit the "Submit for Approval" button the Visualforce email that is sent to approver's also captures the Comments in the pop-up window that is written in the Process Instance step. Has anyone successfully done this? I found this code Capture Comments in Component
Capture Comments (https://gist.github.com/douglascayers/46bb1e92be9909d60fee)  and although it seems it should work the Comments are coming through as blank. The sql in the class does grab the comment I need. Even if I hard-code the Quote number in the Visualforce template when I save it previews the comments I need. Any advice would be appreciated! 

This is my Visualforce email
<messaging:emailTemplate subject="Quote Number: {!relatedTo.Name} Approval Request from: {!relatedTo.Opportunity_Owner__c} for {!relatedTo.Opportunity_Name_Without_Stage__c} totaling {!relatedTo.Formatted_Net_Amount__c}" recipientType="User" relatedToType="SBQQ__Quote__c" >
    <messaging:htmlEmailBody >
        <html>
            <head>
                <style type="text/css">
                .emph {
                    font-weight: bold;
                }
                
                </style>
            </head>
            <body>
                <br/>
                <div style="width: 90%;margin: 0 auto;">
                <!--
                    <p>Payment terms: <span style="font-weight: bold;">{!relatedTo.SBQQ__PaymentTerms__c}</span></p>
                    <p>Shipping terms: <span style="font-weight: bold;">{!relatedTo.Shipping_Terms__c}</span></p>
                    <p>Quote expiry date: <span style="font-weight: bold;">{!relatedTo.SBQQ__ExpirationDate__c}</span></p>
                    <p>Quote description: <span style="font-weight: bold;">{!relatedTo.Description__c}</span></p>
                    <p>Quote comments: <span style="font-weight: bold;">{!relatedTo.SBQQ__Notes__c}</span></p>
                    <p>Freight (if applicable): <span style="font-weight: bold;">{!relatedTo.Shipping_and_Handling__c}</span></p>
                    <p>Tax (if applicable): <span style="font-weight: bold;">{!relatedTo.Tax__c}</span></p>
                -->
                    <apex:OutputLabel value="Account Name: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.SBQQ__Account__r.Name}"/><br/>
                    <apex:OutputLabel value="Payment terms: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.SBQQ__PaymentTerms__c}"/><br/>
                    <apex:OutputLabel value="Shipping terms: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.Shipping_Terms__c}"/><br/>
                    <apex:OutputLabel value="Quote expiry date: " /><span style="font-weight: bold;"><apex:outputField value="{!relatedTo.Expiration_Date_formula__c}"/></span><br/>
                    <apex:OutputLabel value="Quote description: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.Description__c}"/><br/>
                    Comments: <c:ApprovalRequestComments relatedToId="{!relatedTo.Id}"/><br/>
                    <apex:OutputLabel value="Quote comments: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.Additional_Comments__c}" escape="false"/><br/>
                    <apex:OutputLabel rendered="{!!ISBLANK(relatedTo.Shipping_and_Handling__c)}" value="Freight: "/><span style="font-weight: bold;">
                    <apex:outputtext rendered="{!!ISBLANK(relatedTo.Shipping_and_Handling__c)}" value="{!relatedTo.SBQQ__Opportunity2__r.CurrencyISOCode}" />
                    <apex:outputText rendered="{!!ISBLANK(relatedTo.Shipping_and_Handling__c)}" value="{0, number, ###,###,###.00}">
                        <apex:param value="{!relatedTo.Shipping_and_Handling__c}" />
                    </apex:outputText></span><br/>
                    <apex:OutputLabel rendered="{!!ISBLANK(relatedTo.Tax__c)}" value="Tax: "/><span style="font-weight: bold;">
                    <apex:outputtext rendered="{!!ISBLANK(relatedTo.Tax__c)}" value="{!relatedTo.SBQQ__Opportunity2__r.CurrencyISOCode}" />
                    <apex:outputText rendered="{!!ISBLANK(relatedTo.Tax__c)}" value="{0, number, ###,###,###.00}">
                    <apex:param value="{!relatedTo.Tax__c}" />
                    </apex:outputText></span><br/>
                    <c:CPQQuoteDetails quote="{!relatedTo}"/><br/>
                    <apex:outputlink value="{!LEFT($Api.Partner_Server_URL_140,FIND('.com',$Api.Partner_Server_URL_140)+4)+relatedTo.Id}">Please click this link to approve or reject the record.</apex:outputlink>
                </div>
            </body>
        </html>

 
I have a Batch class below (also a scheduled class). I am trying to write the test class using a HTTPCalloutMock but am really struggling). Example I'm trying to follow below but I don't have an getInfoFromExternalService() in MyBatchClass.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm

Any advice would be appreciated. Thank you.




global class MyBatchClass implements Database.Batchable<sObject>,Database.AllowsCallouts, Database.Stateful {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        System.debug('START METHOD');
        String Query= 'SELECT salesforceid__c,Id, number_of_services_in_use__c FROM Account WHERE salesforceid__c != null';
            return Database.getQueryLocator(Query);
    }
    global void execute(Database.BatchableContext bc, List<Account> records){
        System.debug('EXECUTE METHOD');
        // process each batch of records
        String Token ='eyJhbGciOiJSUzI1NiIsImtpZCI6Im1hYXNfcHJvZF8yMDIwMDMyNiIsInR5cCI6IkpXVCJ9.eyJvcmciOiJzYWxlc2ZvcmNlIiwib3JnVHlwZSI6IkVOVEVSUFJJU0UiLCJzdWIiOiJyd3Jqdzl2ZHU2cCIsInBlcm1pc3Npb25zIjoiQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUJBPSIsImFwaVRva2VuSWQiOiJqZW44bjN3aGthciIsImlzcyI6IlNvbGFjZSBDb3Jwb3JhdGlvbiIsImlhdCI6MTU5ODI5MDg3N30.FPfTJFwPfhW3qrEMCcjcfNj-SO8IDMo7MiurTqFcTu2GIStNAjVcjFHD1ESS_3Feo95n6Se_u7ifyee3uLwTTZJknskFn9FB-1ZCFzo0jRKz6TigIzc7WEpFPvbZt4L_MmvLa7eSqM5ovewt9nAtQ1ttJFm7a_35lMsLQu5Bf3f-WbuCjE-POzFnBWASQetCj63TAdgkYu1wNPqZmavJESLlg6Wv6oWf2H5HI_m9fW7Vt2TypQuhIz0Q25iFQoYPKWmseDxU-EUQIwJ1tSqYSuyDNWpFDhEqwTAyBLz4cu-8a-m29caaeG0eIWxIydcMmxq68THY4KTn9Rtmxy_Yug';
        // Initiating the http request
        Http http1 = new http();
        HttpRequest request = new HttpRequest();
        // Adding the paramters for the request
        request.setTimeout(120000);
        request.setEndpoint('https://solace.cloud/api/v0/analytics/organizations');
        request.setMethod('GET');
        request.setHeader('Authorization', 'Bearer '+Token);
        Httpresponse response1 = http1.send(request);
        system.debug('Data response= '+response1.getBody());
        //create a list so we do one insert for all the Metrics records
        List<Cloud_Usage_Metrics__c> newMetrics = new List<Cloud_Usage_Metrics__c>();
        // Logic to map and update the account object
        if (response1.getStatusCode() == 200) {
            // Deserialize the JSON string into collections of primitive data types.
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response1.getBody());
            // Cast the values in the 'accountCloudMetrics' key as a list
            List<Object> data = (List<Object>) results.get('data');
            System.debug('Received the following metrics:');
            for (Object metric: data) {
                Map<String, Object> i = (Map<String, Object>)metric;
                System.debug(i.get('salesforceId'));
               for(Account a: records){
                        if (a.salesforceid__c == i.get('salesforceId')) {
                            Cloud_Usage_Metrics__c met = new Cloud_Usage_Metrics__c(
                                Metric_Name__c='NumberOfMessages',
                                Metric_Date__c=system.today(),
                                Metric_Value__c=Integer.valueOf(i.get('brokerMessageCount')),
                                Account__c=a.id);
                            newMetrics.add(met);
                    }
                }
            //insert newMetrics(met);
            }
        } else {
            System.debug('Callout failed: ' + response1);
        } 
        insert newMetrics;
        update records;
    }
    global void finish(Database.BatchableContext bc){ }  
}

 
Hello, 

I have a Apex class that select records where a field > 0. It then loops through these leads and creates a record in a custom object (Metrics__c). Based on the date it creates a record with a 0 value or with a value > 0. The class works great (tested in Dev Console as a batch) but I'm going in cirlces trying to get the test class past 61%. Any help would be appreciated!

Apex Class

global class MetricProcessor implements Database.Batchable <SObject>,Schedulable {
//START METHOD
global Database.QueryLocator start(Database.BatchableContext bc){

    
    String Query= 'select Id, Console_Logins__c, Console_Last_Logins_Date_Field__c, EP_Catalog__c, EP_Catalog_Date_Field__c, EP_Designer__c, EP_Designer_Date_Field__c, EP_Discovery__c,EP_Discovery_Date_Field__c From Lead where Console_Logins__c > 0';

    return Database.getQueryLocator(Query);

        }

//EXECUTE METHOD

global void execute(Database.BatchableContext bc, List<Lead> scope){

    for(Lead l: scope){

        IF (l.Console_Last_Logins_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='ConsoleLogins',

        Metric_Value__c=l.Console_Logins__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='ConsoleLogins',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Catalog_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPCatalog',

        Metric_Value__c=l.EP_Catalog__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPCatalog',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Designer_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDesigner',

        Metric_Value__c=l.EP_Designer__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDesigner',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Discovery_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDiscovery',

        Metric_Value__c=l.EP_Discovery__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDiscovery',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
    }

    update scope;

}


   

//FINISH METHOD

global void finish(Database.BatchableContext bc){

    Id job= bc.getJobId();

    System.debug(job);

}

 

 global void execute(SchedulableContext SC) {

 MetricProcessor l= new MetricProcessor();

ID batchprocessid = Database.executeBatch(l);

}

}

Test Class

@istest
private class MetricProcessorTest {
    @istest

    static void tetslead(){
        List<Lead> l= new List<Lead>();
        lead l1= new Lead();
        l1.LastName='Chaytor';
        l1.Company='Solace';
        l1.Status='Working';
        l1.Console_Logins_Last_Modified__c = system.now();
        l1.Console_Logins__c = 2;
        l1.EP_Catalog_Last_Modified__c = system.now()-2;
        l1.EP_Catalog__c = 0;
        l1.EP_Designer_Last_Modified__c = system.now()-2;
        l1.EP_Designer__c = 0;
        l1.EP_Discovery_Last_Modified__c = system.now();
        l1.EP_Discovery__c = 1;
        l1.LeadSource='Dreamforce';
        l.add(l1);
        insert l;
        
      List<Metrics__c> m= new List<Metrics__c>();
        Metrics__c m1= new Metrics__c();
        m1.Lead__c = l1.Id;
        m1.Name = 'ConsoleLogins';
        m1.Metric_Value__c = 2;
       // m1.Metric_Date__c = system.today();
        
        m.add(m1);
        insert m;
        
        List<Metrics__c> m2= new List<Metrics__c>();
        Metrics__c m3= new Metrics__c();
        m3.Lead__c = l1.Id;
        m3.Name = 'EPCatalog';
        m3.Metric_Value__c = 0;
        //m3.Metric_Date__c = system.today()-;
        
        m2.add(m3);
        insert m2;
        
        List<Metrics__c> m4= new List<Metrics__c>();
        Metrics__c m5= new Metrics__c();
        m5.Lead__c = l1.Id;
        m5.Name = 'EPDesigner';
        m5.Metric_Value__c = 0;
        //m3.Metric_Date__c = system.today()-;
        
        m4.add(m5);
        insert m4;
        
        List<Metrics__c> m7= new List<Metrics__c>();
        Metrics__c m8= new Metrics__c();
        m8.Lead__c = l1.Id;
        m8.Name = 'EPDiscovery';
        m8.Metric_Value__c = 1;
        //m3.Metric_Date__c = system.today()-;
        
        m7.add(m8);
        insert m7;

        
        
    Test.startTest();
    MetricProcessor lp= new MetricProcessor();
    Id jobid= Database.executeBatch(lp);
        String sch = '0 0 * * * ?';
 
system.schedule('ReassignAccountOwner', sch, lp);

       
     
    
 
    Test.stopTest();

    }

}
Hi all, 

I am creating a Visual Force page (added to layout) to show a pop-up with the CPQ Quote object loads but it's not actually doing anything. I only dabble in development so any advice is appreciated! Thank you! Here is the VF.

<apex:page StandardController="SBQQ__Quote__c">
<script> window.document.onload = new function(e)
{ if(!SBQQ__Quote__c.SBQQ__ExpirationDate__c < TODAY())
{ alert("Expiry Date is in the Past"); }
}
</script>
</apex:page>

As I cannot capture the "Submit or Approval" click without creating a custom button (as far as I can tell) and already have a Validation rule for when they edit the page this was a solution for any Quotes they do NOT edit before hitting "Submit for Approval".
Hello, 

I have a Apex class that select records where a field > 0. It then loops through these leads and creates a record in a custom object (Metrics__c). Based on the date it creates a record with a 0 value or with a value > 0. The class works great (tested in Dev Console as a batch) but I'm going in cirlces trying to get the test class past 61%. Any help would be appreciated!

Apex Class

global class MetricProcessor implements Database.Batchable <SObject>,Schedulable {
//START METHOD
global Database.QueryLocator start(Database.BatchableContext bc){

    
    String Query= 'select Id, Console_Logins__c, Console_Last_Logins_Date_Field__c, EP_Catalog__c, EP_Catalog_Date_Field__c, EP_Designer__c, EP_Designer_Date_Field__c, EP_Discovery__c,EP_Discovery_Date_Field__c From Lead where Console_Logins__c > 0';

    return Database.getQueryLocator(Query);

        }

//EXECUTE METHOD

global void execute(Database.BatchableContext bc, List<Lead> scope){

    for(Lead l: scope){

        IF (l.Console_Last_Logins_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='ConsoleLogins',

        Metric_Value__c=l.Console_Logins__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='ConsoleLogins',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Catalog_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPCatalog',

        Metric_Value__c=l.EP_Catalog__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPCatalog',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Designer_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDesigner',

        Metric_Value__c=l.EP_Designer__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDesigner',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Discovery_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDiscovery',

        Metric_Value__c=l.EP_Discovery__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDiscovery',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
    }

    update scope;

}


   

//FINISH METHOD

global void finish(Database.BatchableContext bc){

    Id job= bc.getJobId();

    System.debug(job);

}

 

 global void execute(SchedulableContext SC) {

 MetricProcessor l= new MetricProcessor();

ID batchprocessid = Database.executeBatch(l);

}

}

Test Class

@istest
private class MetricProcessorTest {
    @istest

    static void tetslead(){
        List<Lead> l= new List<Lead>();
        lead l1= new Lead();
        l1.LastName='Chaytor';
        l1.Company='Solace';
        l1.Status='Working';
        l1.Console_Logins_Last_Modified__c = system.now();
        l1.Console_Logins__c = 2;
        l1.EP_Catalog_Last_Modified__c = system.now()-2;
        l1.EP_Catalog__c = 0;
        l1.EP_Designer_Last_Modified__c = system.now()-2;
        l1.EP_Designer__c = 0;
        l1.EP_Discovery_Last_Modified__c = system.now();
        l1.EP_Discovery__c = 1;
        l1.LeadSource='Dreamforce';
        l.add(l1);
        insert l;
        
      List<Metrics__c> m= new List<Metrics__c>();
        Metrics__c m1= new Metrics__c();
        m1.Lead__c = l1.Id;
        m1.Name = 'ConsoleLogins';
        m1.Metric_Value__c = 2;
       // m1.Metric_Date__c = system.today();
        
        m.add(m1);
        insert m;
        
        List<Metrics__c> m2= new List<Metrics__c>();
        Metrics__c m3= new Metrics__c();
        m3.Lead__c = l1.Id;
        m3.Name = 'EPCatalog';
        m3.Metric_Value__c = 0;
        //m3.Metric_Date__c = system.today()-;
        
        m2.add(m3);
        insert m2;
        
        List<Metrics__c> m4= new List<Metrics__c>();
        Metrics__c m5= new Metrics__c();
        m5.Lead__c = l1.Id;
        m5.Name = 'EPDesigner';
        m5.Metric_Value__c = 0;
        //m3.Metric_Date__c = system.today()-;
        
        m4.add(m5);
        insert m4;
        
        List<Metrics__c> m7= new List<Metrics__c>();
        Metrics__c m8= new Metrics__c();
        m8.Lead__c = l1.Id;
        m8.Name = 'EPDiscovery';
        m8.Metric_Value__c = 1;
        //m3.Metric_Date__c = system.today()-;
        
        m7.add(m8);
        insert m7;

        
        
    Test.startTest();
    MetricProcessor lp= new MetricProcessor();
    Id jobid= Database.executeBatch(lp);
        String sch = '0 0 * * * ?';
 
system.schedule('ReassignAccountOwner', sch, lp);

       
     
    
 
    Test.stopTest();

    }

}
Hello, it's been requested that when our users hit the "Submit for Approval" button the Visualforce email that is sent to approver's also captures the Comments in the pop-up window that is written in the Process Instance step. Has anyone successfully done this? I found this code Capture Comments in Component
Capture Comments (https://gist.github.com/douglascayers/46bb1e92be9909d60fee)  and although it seems it should work the Comments are coming through as blank. The sql in the class does grab the comment I need. Even if I hard-code the Quote number in the Visualforce template when I save it previews the comments I need. Any advice would be appreciated! 

This is my Visualforce email
<messaging:emailTemplate subject="Quote Number: {!relatedTo.Name} Approval Request from: {!relatedTo.Opportunity_Owner__c} for {!relatedTo.Opportunity_Name_Without_Stage__c} totaling {!relatedTo.Formatted_Net_Amount__c}" recipientType="User" relatedToType="SBQQ__Quote__c" >
    <messaging:htmlEmailBody >
        <html>
            <head>
                <style type="text/css">
                .emph {
                    font-weight: bold;
                }
                
                </style>
            </head>
            <body>
                <br/>
                <div style="width: 90%;margin: 0 auto;">
                <!--
                    <p>Payment terms: <span style="font-weight: bold;">{!relatedTo.SBQQ__PaymentTerms__c}</span></p>
                    <p>Shipping terms: <span style="font-weight: bold;">{!relatedTo.Shipping_Terms__c}</span></p>
                    <p>Quote expiry date: <span style="font-weight: bold;">{!relatedTo.SBQQ__ExpirationDate__c}</span></p>
                    <p>Quote description: <span style="font-weight: bold;">{!relatedTo.Description__c}</span></p>
                    <p>Quote comments: <span style="font-weight: bold;">{!relatedTo.SBQQ__Notes__c}</span></p>
                    <p>Freight (if applicable): <span style="font-weight: bold;">{!relatedTo.Shipping_and_Handling__c}</span></p>
                    <p>Tax (if applicable): <span style="font-weight: bold;">{!relatedTo.Tax__c}</span></p>
                -->
                    <apex:OutputLabel value="Account Name: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.SBQQ__Account__r.Name}"/><br/>
                    <apex:OutputLabel value="Payment terms: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.SBQQ__PaymentTerms__c}"/><br/>
                    <apex:OutputLabel value="Shipping terms: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.Shipping_Terms__c}"/><br/>
                    <apex:OutputLabel value="Quote expiry date: " /><span style="font-weight: bold;"><apex:outputField value="{!relatedTo.Expiration_Date_formula__c}"/></span><br/>
                    <apex:OutputLabel value="Quote description: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.Description__c}"/><br/>
                    Comments: <c:ApprovalRequestComments relatedToId="{!relatedTo.Id}"/><br/>
                    <apex:OutputLabel value="Quote comments: " /><apex:outputText style="font-weight: bold;" value="{!relatedTo.Additional_Comments__c}" escape="false"/><br/>
                    <apex:OutputLabel rendered="{!!ISBLANK(relatedTo.Shipping_and_Handling__c)}" value="Freight: "/><span style="font-weight: bold;">
                    <apex:outputtext rendered="{!!ISBLANK(relatedTo.Shipping_and_Handling__c)}" value="{!relatedTo.SBQQ__Opportunity2__r.CurrencyISOCode}" />
                    <apex:outputText rendered="{!!ISBLANK(relatedTo.Shipping_and_Handling__c)}" value="{0, number, ###,###,###.00}">
                        <apex:param value="{!relatedTo.Shipping_and_Handling__c}" />
                    </apex:outputText></span><br/>
                    <apex:OutputLabel rendered="{!!ISBLANK(relatedTo.Tax__c)}" value="Tax: "/><span style="font-weight: bold;">
                    <apex:outputtext rendered="{!!ISBLANK(relatedTo.Tax__c)}" value="{!relatedTo.SBQQ__Opportunity2__r.CurrencyISOCode}" />
                    <apex:outputText rendered="{!!ISBLANK(relatedTo.Tax__c)}" value="{0, number, ###,###,###.00}">
                    <apex:param value="{!relatedTo.Tax__c}" />
                    </apex:outputText></span><br/>
                    <c:CPQQuoteDetails quote="{!relatedTo}"/><br/>
                    <apex:outputlink value="{!LEFT($Api.Partner_Server_URL_140,FIND('.com',$Api.Partner_Server_URL_140)+4)+relatedTo.Id}">Please click this link to approve or reject the record.</apex:outputlink>
                </div>
            </body>
        </html>

 
Hello, 

I have a Apex class that select records where a field > 0. It then loops through these leads and creates a record in a custom object (Metrics__c). Based on the date it creates a record with a 0 value or with a value > 0. The class works great (tested in Dev Console as a batch) but I'm going in cirlces trying to get the test class past 61%. Any help would be appreciated!

Apex Class

global class MetricProcessor implements Database.Batchable <SObject>,Schedulable {
//START METHOD
global Database.QueryLocator start(Database.BatchableContext bc){

    
    String Query= 'select Id, Console_Logins__c, Console_Last_Logins_Date_Field__c, EP_Catalog__c, EP_Catalog_Date_Field__c, EP_Designer__c, EP_Designer_Date_Field__c, EP_Discovery__c,EP_Discovery_Date_Field__c From Lead where Console_Logins__c > 0';

    return Database.getQueryLocator(Query);

        }

//EXECUTE METHOD

global void execute(Database.BatchableContext bc, List<Lead> scope){

    for(Lead l: scope){

        IF (l.Console_Last_Logins_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='ConsoleLogins',

        Metric_Value__c=l.Console_Logins__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='ConsoleLogins',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Catalog_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPCatalog',

        Metric_Value__c=l.EP_Catalog__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPCatalog',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Designer_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDesigner',

        Metric_Value__c=l.EP_Designer__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDesigner',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Discovery_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDiscovery',

        Metric_Value__c=l.EP_Discovery__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDiscovery',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
    }

    update scope;

}


   

//FINISH METHOD

global void finish(Database.BatchableContext bc){

    Id job= bc.getJobId();

    System.debug(job);

}

 

 global void execute(SchedulableContext SC) {

 MetricProcessor l= new MetricProcessor();

ID batchprocessid = Database.executeBatch(l);

}

}

Test Class

@istest
private class MetricProcessorTest {
    @istest

    static void tetslead(){
        List<Lead> l= new List<Lead>();
        lead l1= new Lead();
        l1.LastName='Chaytor';
        l1.Company='Solace';
        l1.Status='Working';
        l1.Console_Logins_Last_Modified__c = system.now();
        l1.Console_Logins__c = 2;
        l1.EP_Catalog_Last_Modified__c = system.now()-2;
        l1.EP_Catalog__c = 0;
        l1.EP_Designer_Last_Modified__c = system.now()-2;
        l1.EP_Designer__c = 0;
        l1.EP_Discovery_Last_Modified__c = system.now();
        l1.EP_Discovery__c = 1;
        l1.LeadSource='Dreamforce';
        l.add(l1);
        insert l;
        
      List<Metrics__c> m= new List<Metrics__c>();
        Metrics__c m1= new Metrics__c();
        m1.Lead__c = l1.Id;
        m1.Name = 'ConsoleLogins';
        m1.Metric_Value__c = 2;
       // m1.Metric_Date__c = system.today();
        
        m.add(m1);
        insert m;
        
        List<Metrics__c> m2= new List<Metrics__c>();
        Metrics__c m3= new Metrics__c();
        m3.Lead__c = l1.Id;
        m3.Name = 'EPCatalog';
        m3.Metric_Value__c = 0;
        //m3.Metric_Date__c = system.today()-;
        
        m2.add(m3);
        insert m2;
        
        List<Metrics__c> m4= new List<Metrics__c>();
        Metrics__c m5= new Metrics__c();
        m5.Lead__c = l1.Id;
        m5.Name = 'EPDesigner';
        m5.Metric_Value__c = 0;
        //m3.Metric_Date__c = system.today()-;
        
        m4.add(m5);
        insert m4;
        
        List<Metrics__c> m7= new List<Metrics__c>();
        Metrics__c m8= new Metrics__c();
        m8.Lead__c = l1.Id;
        m8.Name = 'EPDiscovery';
        m8.Metric_Value__c = 1;
        //m3.Metric_Date__c = system.today()-;
        
        m7.add(m8);
        insert m7;

        
        
    Test.startTest();
    MetricProcessor lp= new MetricProcessor();
    Id jobid= Database.executeBatch(lp);
        String sch = '0 0 * * * ?';
 
system.schedule('ReassignAccountOwner', sch, lp);

       
     
    
 
    Test.stopTest();

    }

}