I have an apex trigger that do the update the createddate field on parent when the child record is created. I'm not able to get the code coverage for the createddate field.

Thanks in advance

Here is the trigger:

trigger TriggerUpdateImplTestDate on Implementation_Facilities_In_Test__c (after insert) {
   Map<Id,Date> parentimpl = new Map<Id,Date>();
   for(Implementation_Facilities_In_Test__c imptest : trigger.new){
    List<Parent_Implementation__c> parentImplToUpdate = [Select Id,Implementation_Test_Results_Created_Date__c from Parent_Implementation__c where id in:parentimpl.keySet()];
    for(Parent_Implementation__c pit : parentImplToUpdate ){
    pit.Implementation_Test_Results_Created_Date__c = parentimpl.get(pit.Id);
    update parentImplToUpdate;   

Test Class:


public class ImplementationupdatedateTests{

public static testMethod void testImplementationDateupdate() {
Implementation_Facilities_In_Test__c impltest=New Implementation_Facilities_In_Test__c ();
impltest.Name= 'Test1';
insert impltest;

 Parent_Implementation__c impl=New Parent_Implementation__c();
 insert impl;

  • Which line of code?
    – sfdcfox
    Jun 24, 2015 at 16:41
  • Can you add the test class that you're using? Jun 24, 2015 at 16:43
  • I'm not able to assign a created date on the test record that I'm creating for the Implementation_Facilities_In_Test__c object. Jun 24, 2015 at 16:44
  • Unless you have audit fields turned on I do not believe you can set the value of createddate standard field?? Not to mention the line of code impltest.createdDate= is invalid as there is nothing after the '='
    – Eric
    Jun 24, 2015 at 17:43
  • CreatedDate can be set while mocking unit test data using either the Json.deserialize trick salesforce.stackexchange.com/questions/62/… or laoding test data from static resources
    – cropredy
    Jun 24, 2015 at 17:57

1 Answer 1


At first glance it looks like you need to insert the parent before the child record in your test and assign the child to the parent before inserting the child record.
Side note: couldn't you do this with a workflow rule or process builder vs a trigger?

Not the answer you're looking for? Browse other questions tagged .