• Aaron Olson 26
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I am looking for some help with a test class. My code looks at when a lead comes in and creates a taks with an after business hours flag. I am trying creat a test class that uses business hours to test the following code. I havnt figured out a way to simulate after hours. 
 
trigger Working_Lead_business on Lead (after insert) {
    public datetime mydate = system.now();
    List<Task> tsk_lst = new list<task>{};
    BusinessHours bh = [select id from businesshours where id = '01m50000000LjJ5'];
    Boolean isWithin = BusinessHours.isWithin(bh.id, mydate);
    system.debug('BusinessHours = ' + isWithin);
    
    For(Lead l: Trigger.new) {
        if(l.Status == 'New' && isWithin == false && (l.Country != 'UK' || l.Country != 'United Kingdom')){
            Task taskcreate = new Task();
            taskcreate.OwnerId = '00550000005ThR4';
            taskcreate.WhoId = l.id;
            taskcreate.ReminderDateTime = date.today();
            taskcreate.Subject = 'Call';
            taskcreate.Status = 'Completed';
            tsk_lst.add(taskcreate);
        }
    }
    upsert tsk_lst;
}
Thank you for any help.