and this is as far as I've been able to get with creating the test class:global class TimeZoneConverter
{
@InvocableMethod(label='Convert Timezone DateTime' description='Converts a date time timezone string to a DateTime value')
public static List<Datetime> UTCdateValue(List<TimezoneConvertRequest> ConvertMe)
{
Timezone tz = Timezone.getTimeZone(ConvertMe[0].tzRequest); //now I have an official Timezone datatype variable tz
Datetime dt = Datetime.parse(ConvertMe[0].dtRequest.format()); //now I have a UTC Datetime string
Integer offsetMS = tz.getOffset(dt); //now I have the Milliseconds difference between the timezone selected and the UTC datetime string
Integer offsetHrs = (((offsetMS / 1000)/60)/60)*-1; //now I have the offset in hours
Datetime adjdt = dt.addHours(offsetHrs); //should be the adjusted value.
List<Datetime> returnMe = new List<Datetime>();
returnMe.add(adjdt);
return returnMe;
}
global class TimezoneConvertRequest {
@InvocableVariable(required=true)
public String tzRequest;
@InvocableVariable(required=true)
public Datetime dtRequest;
}
}
I'm getting an error of "Static methods cannot be invoked through an Object instance: UTCdateValue(List)" on line 13 - the one that reads:@isTest
class TimeZoneConverterTest {
@isTest static void testTimezoneConvertRequest() {
Test.startTest();
DateTime BroadcastItemDateTimeTest = Datetime.parse('2016-01-01 13:00:00');
string Timezone_Selected = 'US/Eastern';
List<TimeZoneConverter.TimezoneConvertRequest> testingThis = new List<TimeZoneConverter.TimezoneConvertRequest>();
TimeZoneConverter.TimezoneConvertRequest ConvertMeTest = new TimeZoneConverter.TimezoneConvertRequest();
ConvertMeTest.tzRequest = Timezone_Selected;
ConvertMeTest.dtRequest = BroadcastItemDateTimeTest;
testingThis.add(ConvertMeTest);
TimeZoneConverter ConvertTest = new TimeZoneConverter();
ConvertTest.UTCdateValue(TestingThis);
DateTime testResponse = ConvertTest[0];
Test.stopTest();
System.assertEquals(Datetime.parse('2016-01-01 13:00:00'), testResponse);
}
}
I've gone around and around on this one and can't find a resource that spells it out quite clearly enough for me... Can someone help me get my code coverage up to snuff?Thanks!AdamConvertTest.UTCdateValue(TestingThis);
Adam Coppin 13
Thank you! I don't consider myself a developer, and I've been trying to create a test class for hours, thanks to this publication I was able to do it in minutes!