You need to sign in to do that
Don't have an account?
Felix Jong Seok Chae
Trigger is not firing in Test Method
I created a new case with anonymous window and trigger succesfully set a field of a new case.
However, when I tried to create a new case (w/ same fields' values as one before) in test method, it does not update a field of this case via trigger.
I followed the help from the forum saying that I should fetch a case using soql after insertion, but it did not work.
Can someone please help me on this?
However, when I tried to create a new case (w/ same fields' values as one before) in test method, it does not update a field of this case via trigger.
I followed the help from the forum saying that I should fetch a case using soql after insertion, but it did not work.
Can someone please help me on this?
@isTest static void singleCaseInsertion() { Case newCase = new Case(...); insert newCase; test.startTest(); Case newCasePtr = [Select casenumber, id, similarcases__c from case where id = :newCase.id]; String newCaseSimCases = newCasePtr.similarCases__c; test.stopTest(); System.assert(newCaseSimCases != null); // I get null value for this field, which is wrong. }
Have something along following lines..
Hope it helps!
I intentionally make new Case(...) as I don't want to show all fields in my post, but I did set fields for this new case.
I followed your code, but still have same assertion error. I'm sure my trigger works when I create the case via anonymous window as I can see similarcases__c field is not null after inserting a new case.
I think you may need to check if the case is inserted or not and what value in coming in similarcases__c
Have below statement After line 10
Have below statement before line 15 in above trigger,
Make sure that newCase.Id is not null and similarcases__c is not null
insert newCase;
add a line
Update newCase;
If the trigger calls other methods then we need to make sure that whatever the required record creation is required for other methods, are taken cared as well.
What daya type is similarCases__c?
I tried the integer comparison, but didn't work either.
I found the solution and it happened because test method was not accessible to sf database. I used "@isTest(SeeAllData=true)" above the test class, and it worked.