0

I need help I'm losing my mid. I have a working trigger and I'm writing a test class.
My data is isolated ( no @seeAllData=true)
I create a master and children objects in my set up.
I insert the objects and validate they all have id. I run the query that runs in the after delete trigger on master and in my test class it fetches the items but in the trigger it self no results are not pulled
WHY?

8
  • Have a look at the debug log when the test case runs to see what is going on before the after delete trigger fires. Commented Dec 19, 2014 at 0:32
  • That's what I've been doing for the past hour. There is no before delete trigger. Other triggers are disabled. The same query ( i print it out in both places and see the selection id is the same) returns children in the test class but not in the trigger.
    – user682217
    Commented Dec 19, 2014 at 0:38
  • 1
    I'm assuming that the records aren't being deleted which is what's making the trigger run?
    – Matt Lacey
    Commented Dec 19, 2014 at 0:43
  • the master object is. I do call delete master in the test. I see the trigger kicks in. It runs a query "select detail from master where master id = : " and gets no results so it gives up. The same id...the same query, no results in trigger all results directly in test class.....I need a shrink
    – user682217
    Commented Dec 19, 2014 at 0:52
  • @user682217 If this is an after delete trigger and you are using the ID of the master record that was just deleted in the SOQL query then you won't find it. It has just been deleted. Perhaps you want a before update trigger. Commented Dec 19, 2014 at 1:01

1 Answer 1

3

Based on the comment discussion above, I believe the problem was trying to run a SOQL query in an after update trigger for the record that was just deleted.

The record is indeed deleted at this point, so the SOQL query won't find it (with the exception of the ALL ROWS keywords).

If you need to run a SOQL query for the record being deleted try a before delete trigger instead. Alternatively, try using the oldMap trigger context variable.

1
  • yes I was using oldMap but it didn't worked in test Thanks
    – user682217
    Commented Dec 19, 2014 at 2:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .