global class addBusinessHours { | |
global class request | |
{ | |
@InvocableVariable (label='Start Date' required = true) | |
global DateTime startDateTime; | |
@InvocableVariable (label='Business Hours Id' required = true) | |
global String businessHoursId; | |
@InvocableVariable (label='Interval To Add (Milliseconds)' required = true) | |
global Long intervalMilliseconds; | |
} | |
global class response | |
{ | |
@InvocableVariable (label='Next Business Date') | |
global DateTime updatedBusinessDate; | |
} | |
@InvocableMethod(label='Professor Flow | Add Business Hours' description='Adds an interval of time from a start Datetime traversing business hours only. Returns the result Datetime in the local time zone.') | |
global static List<response> getUpdatedBusinessDate (List<request> inputParams) | |
{ | |
List<response> responseList = new List<response>(); | |
DateTime updatedDate; | |
if(inputParams != null && inputParams.size()> 0) | |
{ | |
for(request pf : inputParams){ | |
updatedDate = BusinessHours.add(pf.businessHoursId, pf.startDateTime, pf.intervalMilliseconds); | |
response rs = new response(); | |
rs.updatedBusinessDate = updatedDate; | |
responseList.add(rs); | |
} | |
} | |
return responseList; | |
} | |
} |
@isTest | |
global class addBusinessHoursTest | |
{ | |
@isTest static void check_NextBusinessDate() | |
{ | |
Profile sysadminprofile = [select Id, name from profile where Name='System administrator' limit 1]; | |
User adminUser = [select Id,Name from user where profileId= :sysadminprofile.Id and isactive=true limit 1]; | |
BusinessHours bhoursId = [select Id from BusinessHours where Name='Default' limit 1]; | |
System.runAs(adminUser) | |
{ | |
List<addBusinessHours.request> inputparams = new List<addBusinessHours.request>(); | |
//record 1 | |
addBusinessHours.request pf = new addBusinessHours.request(); | |
pf.startDateTime = Datetime.now(); | |
pf.businessHoursId = bhoursId.Id; | |
pf.intervalMilliseconds = 3600000; | |
inputparams.add(pf); | |
Test.startTest(); | |
List<addBusinessHours.response> response = addBusinessHours.getUpdatedBusinessDate(inputparams); | |
Test.stopTest(); | |
System.assertEquals(Datetime.now().date(),response[0].updatedBusinessDate.Date()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment