function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bryan CerratiBryan Cerrati 

Apex Test: setCreatedDate help.

hello there. with the help of Nayana K and the developer community here. i wrote a class to send 2 diffrent sets of emails based on when they are recieved. one set is between the hours of 6pm to 8.59am EST and the other email is sent at 9am to 5.59pm EST. it is 100% working but i have been having trouble using the setCreateDate inside the test class it doesnt seem to be firing within the times i set. 

heres the if statement that does not fire. 
 
if(objLead.CreatedDate.hour() >= 18 || objLead.CreatedDate.hour() <= 8)

no code below this gets covered but everything in the else gets covered. 

here are my tests
 
@isTest 
private class jungoLeadFollowupTest 
{

	@isTest static void zillowNull() 
	{
		Time myTime = Time.newInstance(12, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 5);
		DateTime dt = DateTime.newInstance(myDate, myTime);		
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c = null);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
		
	}
	
	@isTest static void zillowNotNull()
	{
		Time myTime = Time.newInstance(12, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c ='jfrangoulis@unitedmortgage.com');
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);		
		
	}
	@isTest static void afterHourEmailNotNull()
	{
		Time myTime = Time.newInstance(24, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__Zillow_Recipient_Email__c ='jfrangoulis@unitedmortgage.com',
		JungoLeadsFrc__EmailAddress__c = null);
		//newLead.setCreatedDate(newLead.Id, dt);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
	}
	
		@isTest static void emailnull()
	{
		Time myTime = Time.newInstance(24, 0, 0, 0);
		Date myDate = Date.newInstance(2016, 10, 4);
		DateTime dt = DateTime.newInstance(myDate, myTime);
		JungoLeadsFrc__JungoLeads__c newLead = new JungoLeadsFrc__JungoLeads__c(
		JungoLeadsFrc__EmailAddress__c = 'jfrangoulis@unitedmortgage.com',
		JungoLeadsFrc__Zillow_Recipient_Email__c = null);
		insert newLead;
		Test.setCreatedDate(newLead.Id, dt);
		
	}

}

 
Bryan CerratiBryan Cerrati
NOTHING?
lordLoxorlordLoxor
Hi Bryan, just checking after almost 4 years were you able to solve your problem, If yes could you put the answer here may be it would help me out?