You need to sign in to do that
Don't have an account?
TBouscal
Test code getting "List has no rows for assignment to SObject" error
Attempting to track down an issue where I get "List has no rows...".
I've added some debug lines to my trigger and what's throwing me for a loop is the message is occuring within the trigger where there is no code and no calls to anything.
Is there a way, without going through every trigger & class, to track where the issue is occurring?
I've added some debug lines to my trigger and what's throwing me for a loop is the message is occuring within the trigger where there is no code and no calls to anything.
if(Trigger.isBefore && Trigger.isInsert){ System.debug('Case.Trigger.isBefore && Case.Trigger.isInsert'); } if(Trigger.isAfter && Trigger.isUpdate) { System.debug('Case.Trigger.isAfter && Case.Trigger.isUpdate');The debug line showing the isBefore && isInsert shows in the log, then the error, then the isAfter && isUpdate.
Is there a way, without going through every trigger & class, to track where the issue is occurring?
Thanks for all the input folks!
All Answers
Can you share your complete code? The codes and information you have given may not be sufficient to recreate and fix the issue.
Here's the trigger, do you need to see the test class or class I'm testing? [SendMail.CaseContact(Trigger.new);]
The error should be occurring on a line of code that has the form:
SObject obj = [SELECT Id FROM SObject LIMIT 1];
There's nothing like that in your trigger, so I suspect it's either in the test class or in one of the methods that the trigger calls. The call stack will tell us exactly (class and line number) where the exception is being thrown. My guess is that, because the test code does not use "SeeAllData=true", there is something being queried that exists in production, but not in your test.
It seems part, if not all of the issue, is with the order of execution. I'm inserting a Case then adding a Task to it to create my test data. I understand that the after update fires on an insert as well so how do I bypass that while creating my test data so updating the Case will cause the after trigger to fire but creating it will not?
I have to put the call inside the test on line 22 above because I don't want it to fire twice but doing so causes it to fire before the test data is prepared and not fire once the data is prepared.
If you have not found a solution yet, if my understanding is right, your problem is to bypass trigger while creating a test data.
If yes, you may try,
In your trigger, you may put all your logic under the condition if Test.isRunningTest() is false. Let me know if you have already tried it.
Hope this helps!
I think my answer lies in startTest/stopTest but I can't get beyond a "Method does not exist or incorrect signature: voice startTest() frmo the type test"
Thanks for all the input folks!