The trigger: enter image description here

What I have been trying for the test class: enter image description here

I am a total noob when it comes to writing these unit tests. I would greatly appreciate any guidance to help me get this figured out.


Your trigger is set to run after a case record is updated however your unit test is only inserting cases and updating contacts. Think about how you would test your trigger in the UI and then attempt to do that via code.

Something like:
Create a case.
Insert the case.
Modify the survey date.
Update the case.

Remember to bulk test as well as use system asserts to validate the expected outcome.

  • So I got 92% test code coverage by writing another method that creates a new case and modifies the survey date. But I get this error output: system.dmlexception: Update failed. First exception on row 0 with ID 50555000000czrunAAA; first error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SurveySent: execution of AfterUpdate. Any ideas what I am doing wrong? – Allen Mann Aug 30 '15 at 16:14
  • 1
    Never mind, I figured it out. Thanks again for all your help. – Allen Mann Aug 30 '15 at 18:29

It is an After Update trigger on Case but you are only updating the Contact within the test class. You need to update the case for the trigger to be executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.