You need to sign in to do that
Don't have an account?
Patrick Maxwell Appfolio
APEX code works great...until I try running a test
Hello Salesforce Coders,
I have a problem, and it's not giving me warm fuzzies inside. Quick disclaimer, I'm not experienced at coding, but I'm learning, and I'm very interested in it. I have written some APEX that will update a field on one SObject based on a field being updated on another SObject. I've bulkified it, and it works great in our sandbox. Even when I dataload 200+ records, it's great, I'm happy. However, now that I've gotten to the step to write test code, I am confounded by my predicament. When I run the code via test the field that needs to be updated (after the update of the other field) will not update, so my final assertion is wrong and my test code fails. I can get more detailed, but I figured I would keep things vague for now, and if anyone is interested, they can respond to this post and throw down some knowledge.
Thanks for your time!
Patrick
I have a problem, and it's not giving me warm fuzzies inside. Quick disclaimer, I'm not experienced at coding, but I'm learning, and I'm very interested in it. I have written some APEX that will update a field on one SObject based on a field being updated on another SObject. I've bulkified it, and it works great in our sandbox. Even when I dataload 200+ records, it's great, I'm happy. However, now that I've gotten to the step to write test code, I am confounded by my predicament. When I run the code via test the field that needs to be updated (after the update of the other field) will not update, so my final assertion is wrong and my test code fails. I can get more detailed, but I figured I would keep things vague for now, and if anyone is interested, they can respond to this post and throw down some knowledge.
Thanks for your time!
Patrick
Testing is tricky, if you are doing the test on sandbox you need to make sure that you insert every record that is in the relationship until we get to the object we are working on. So for example if we have created a trigger on case and we need to write a unit test in that case we begin with creating an account record and then a contact record and then a case record. Once we get the case record we do wat ever manipulations we have to and then insert/update it.
Later for checking the assertion, you need to create another case object and do a SOQL to get all the case information and then do an assert.
Long story short, create all the records from the top most parent object to the current object and do testing.
All Answers
Would help you could share the code you've written so the members can understand the issue better and suggest accordingly.
Testing is tricky, if you are doing the test on sandbox you need to make sure that you insert every record that is in the relationship until we get to the object we are working on. So for example if we have created a trigger on case and we need to write a unit test in that case we begin with creating an account record and then a contact record and then a case record. Once we get the case record we do wat ever manipulations we have to and then insert/update it.
Later for checking the assertion, you need to create another case object and do a SOQL to get all the case information and then do an assert.
Long story short, create all the records from the top most parent object to the current object and do testing.