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
singledotsingledot 

Test Class/ Trigger - fine in Sandbox / not in Developer - update fields on a related object

Just trying to do a simple field update on a related object from another object.

trigger UpdateMilestoneStatus on Assessment__c (after insert, after update){


  Set<ID> mileId = new Set<ID>();
  date mileDate;



  for(Assessment__c a : Trigger.new){
    if (a.Passed_Milestone__c == true){
      mileId.add(a.Related_Milestone__c);
      mileDate = a.Test_Date__c;
      
      

    }
}

  List<Milestones__c> mileList = [SELECT id, Status__c, Actual_Completion_Date__c FROM Milestones__c WHERE id in :mileId ];
  for(integer i = 0 ; i < mileList.size(); i++){
    mileList[i].Status__c = 'Complete';
    mileList[i].Actual_Completion_Date__c = mileDate;

   
    
    }
  


  update mileList;
}

 Think the Trigger is okay but really new to testing and completely confused. All of the fields below as necessary fields due to validations/ lookups/ master-detail. 

 

 

@isTest

private class TestClassChangeMilestoneStatus { 

    static testMethod void validateUpdateMilestoneStatus() {   
    
    
      Contact testContact = new Contact( LastName = 'NewContact' );
      insert testContact;
      testContact = [select Id from Contact where Id = :testContact.Id];
      
      
      Milestones__c testMilestone = new Milestones__c( Name = 'Milestone Test', Anticipated_Completion_Date__c =Date.today(), 
                  Related_to_an_Assessment__c = True, Contact_Name__c = testContact.Id, Status__c = 'In Progress' );
      insert testMilestone;
      testMilestone = [select Id from Milestones__c where Id = :testMilestone.Id];
     
      
      Id rtId = [select Id from RecordType where name='TABE 10 Mathematics Computation' and SObjectType='Assessment__c' limit 1].Id;
     

       Assessment__c a = new Assessment__c(
       
        Contact_Name__c= testContact.ID,
        RecordTypeId = rtId,
        Test_Date__c = Date.today(),
        Total_Score__c = 30,
        Passed_Milestone__c = True,
        Related_Milestone__c = testMilestone.ID); 

        insert a;
        }
}

 Any help would be deeply appreciated! L

Best Answer chosen by Admin (Salesforce Developers) 
singledotsingledot

In the interest of closing this thread, what I found was that a missing test class for ChatterAnswers (this was/is a Salesforce bug) was bringing all my test stats down.