• Jon Hayes CHI
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
Hello,

I'm trying to navigate my way through this apex test case and I've not been successful. Could anyone assist with bringing coverage up from 46%?
Thank you.

Test Class:
@isTest
private class CHIEventsMonitorTest {
    @testSetup 
    static void setup() {
        List<Event__c> events = new List<Event__c>();
        // insert 10 events
        for (Integer i=0;i<10;i++) {
            events.add(new Event__c(name='Event '+i, 
                CreatedDate = DateTime.now(), LastModifiedDate = DateTime.now(), Event_End_Date__c = Date.today(), CHI_Publish_To_Website__c = false, CHI_Status__c = 'Planned', Send_to_Consultants_for_Assignment_c__c = false, EvaluationPilot__c = false, Send_Attendance_Email__c = false, Completed__c = false));
        }
        insert events;
    }
    static testmethod void test() {        
        Test.startTest();
        CHIEventsMonitor uca = new CHIEventsMonitor();
        Id batchId = Database.executeBatch(uca);
        Test.stopTest();
    }
    
}
Note - Most of this was accomplished with the help of Google (obviously, or I probably wouldn't be here)

Batch Class:
global class CHIEventsMonitor implements Database.Batchable<sObject>{
    List<Event__c> eventToUpdate = new List<Event__c>();
    Date dt = date.today();
    String query = 'Select Id, CHI_Status__c, Completed__c, Send_Attendance_Email__c From Event__c WHERE IsFinished__c = FALSE AND Event_End_Date__c =: dt';  

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Event__c> event){
        for(Event__c c : event){
            if(c.Completed__c==FALSE){
                c.Send_Attendance_Email__c = TRUE;
                c.Completed__c = TRUE;
                eventToUpdate .add(c );         
            }

        }
        update eventToUpdate ;
    }

    global void finish(Database.BatchableContext BC){     
    }
}

 
I am building a VF email template that contains a URL to create a record and prefilling some fields on the form. Of the fields is a date field and it only serves as a reference to the user but needs to be readable. I need to remove the time zone/offset from the date that is rendered into my URL. I know how to output the format I want anywhere else in the email but as part of an <a href".. tag I do not know how.

My URL looks like this:
Click<a href="https://na3.salesforce.com/a1B/e?CF00N0L0044062bDo={!relatedTo.Name}&CF00N0L0044062bDo_lkid={!relatedTo.Id}&CF00N0L4400062bDx={!recipient.name}&00N0L0055062bE2='{!relatedTo.Start_Date__c}"> HERE</a> to respond.<br />
But the field "Start Date" renders as :
Fri%20Jul%2014%2000:00:00%20GMT%202017
Is there an equivalent to this:
<apex:outputText value="{0,date,MM/dd/yyyy}"> <apex:param value="{!relatedTo.Start_Date__c}" /> </apex:outputText>

that I can do within the href tag to output the date into my URL in a cleaner format?


 
Hello,

I'm trying to navigate my way through this apex test case and I've not been successful. Could anyone assist with bringing coverage up from 46%?
Thank you.

Test Class:
@isTest
private class CHIEventsMonitorTest {
    @testSetup 
    static void setup() {
        List<Event__c> events = new List<Event__c>();
        // insert 10 events
        for (Integer i=0;i<10;i++) {
            events.add(new Event__c(name='Event '+i, 
                CreatedDate = DateTime.now(), LastModifiedDate = DateTime.now(), Event_End_Date__c = Date.today(), CHI_Publish_To_Website__c = false, CHI_Status__c = 'Planned', Send_to_Consultants_for_Assignment_c__c = false, EvaluationPilot__c = false, Send_Attendance_Email__c = false, Completed__c = false));
        }
        insert events;
    }
    static testmethod void test() {        
        Test.startTest();
        CHIEventsMonitor uca = new CHIEventsMonitor();
        Id batchId = Database.executeBatch(uca);
        Test.stopTest();
    }
    
}
Note - Most of this was accomplished with the help of Google (obviously, or I probably wouldn't be here)

Batch Class:
global class CHIEventsMonitor implements Database.Batchable<sObject>{
    List<Event__c> eventToUpdate = new List<Event__c>();
    Date dt = date.today();
    String query = 'Select Id, CHI_Status__c, Completed__c, Send_Attendance_Email__c From Event__c WHERE IsFinished__c = FALSE AND Event_End_Date__c =: dt';  

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Event__c> event){
        for(Event__c c : event){
            if(c.Completed__c==FALSE){
                c.Send_Attendance_Email__c = TRUE;
                c.Completed__c = TRUE;
                eventToUpdate .add(c );         
            }

        }
        update eventToUpdate ;
    }

    global void finish(Database.BatchableContext BC){     
    }
}

 
I am building a VF email template that contains a URL to create a record and prefilling some fields on the form. Of the fields is a date field and it only serves as a reference to the user but needs to be readable. I need to remove the time zone/offset from the date that is rendered into my URL. I know how to output the format I want anywhere else in the email but as part of an <a href".. tag I do not know how.

My URL looks like this:
Click<a href="https://na3.salesforce.com/a1B/e?CF00N0L0044062bDo={!relatedTo.Name}&CF00N0L0044062bDo_lkid={!relatedTo.Id}&CF00N0L4400062bDx={!recipient.name}&00N0L0055062bE2='{!relatedTo.Start_Date__c}"> HERE</a> to respond.<br />
But the field "Start Date" renders as :
Fri%20Jul%2014%2000:00:00%20GMT%202017
Is there an equivalent to this:
<apex:outputText value="{0,date,MM/dd/yyyy}"> <apex:param value="{!relatedTo.Start_Date__c}" /> </apex:outputText>

that I can do within the href tag to output the date into my URL in a cleaner format?