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
jonathanbernddf20131.387825590468351E12jonathanbernddf20131.387825590468351E12 

Test Class - cannot call 'after update' trigger when updating test record

I'm new to apex and am having difficulty with a test class for a working trigger and class in my sandbox.
The trigger and class I have work after insert and after update on a field value ('Stage') on a parent object. 
If the parent is new, then a new child object is created with a Stage__c field that mirrors the parent object 'Stage' field

I started writing a bulk test class, but as I couldn't get it to properly create new records, I started again from scratch with a single test record.
I insert the test record and a child record is created exactly as it should be. (System.debug, assert etc. confirm).

Then I take that same test parent record and update the 'Stage' field to a new value. The after update trigger should create another new child record with the new 'Stage__c' value and also find the old child record and update a field there. 

Even though System.debug says I've successfully updated the field 'Stage' on the parent object, the trigger is clearly not being called as it doesn't created a second child object.

I'm using oldStage.Stage = 'new value';  update oldStage;  

Guessing the Test environment never really 'saved' my initial record so it doesn't recognize this is a legit update. 

Can you help me understand best practice and solution(s)?

Thanks
pconpcon
Can you please include your trigger code and your test code?  It may be an issue with either your trigger logic or with how you are calling your update in the test code.  Please use the "Add a code sample" button when including your code.
David "w00t!" LiuDavid "w00t!" Liu
Do you have a DML statement in your code to explicitly create your child object?

IE you should have a line somewhere like this:
insert myChildRecords;