You need to sign in to do that
Don't have an account?
Opster
Apex Test class query returns no results in Sandbox
I have a very simple query that I have used in a test class to test a trigger. This same code works in many other orgs, but for some reason returns zero results in one sandbox I am working in.
t.WhoId = [SELECT id FROM Contact LIMIT 1].id;
I see thousands of Contacts in the Sandbox and have tried even creating a new one.
Does anyone know why the code would return zero results and what I should do to fix it?
In test classes you will need to create your own test data
put this line before the query and try again
Contact test_contact = new Contact(FirstName='Orig First Name',LastName='Orig Last Name',Email='orig@email.com');
insert test_contact;
All Answers
In test classes you will need to create your own test data
put this line before the query and try again
Contact test_contact = new Contact(FirstName='Orig First Name',LastName='Orig Last Name',Email='orig@email.com');
insert test_contact;
Your suggestion of course worked. But I am curious why my tests never failed in the past without inserting my own data for the test to run off of? Any ideas there?
I could give you some clues if you can give me an example from your past code. For this issue, if you could mark it as solved, it will help others find solutions.
Because you rprevious test methods use API < 24. In API v24 it changed