I am work on test class for the following code. The code uses the business hours from Salesforce and applies a task to anything lead that comes in after business hours. The issue is I cant get the test class to simulate after hours.
I have tried to just set the isWithin var to false I have tried to add time to the target time. I am running out of ideas.
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);
For(Lead l: Trigger.new) {
if(l.Status == 'New' && isWithin == false){
Task taskcreate = new Task();
taskcreate.OwnerId = '00550000005ThR4';
taskcreate.WhoId = l.id;
taskcreate.Subject = 'email';
taskcreate.Priority = 'Normal';
taskcreate.Type = 'After Hours';
taskcreate.Status = 'Completed';
tsk_lst.add(taskcreate);
}
}
if (tsk_lst == null){
/*Do nothing*/
} else {
upsert tsk_lst;
}
}