function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JoeSpecJoeSpec 

Perplexed by test method

I have a class that contains a test method. this method passes in production and seems to be working fine.

When I run the test on the sandbox though, the test fails.

I took out all my new code.  I refreshed the sandbox (which took 3 days by the way) and still it fails on the sandbox.

 

The code basically calls some soql  and sets 2 fields in an assessment object , previous assessment and next assessment.

The test class makes an assertion to see if the earliest assessment has a null in the previous assessment field as it should.   but instead it links back to one of the other assessments which  the test creates.

 

any ideas on why the difference when running it from the sandbox?

 

also this isn't my code making it a bit more difficult to understand what's going on.

 

thanks,

 

 

hitesh90hitesh90

Hi,

 

This problem is occurs because of you are getting records in your Test class using SOQL query.

these records are exist in production but not in sandbox so it gives error and your test class has not been covered.

 

Solution:

Create dummy(Test) records in your test class rather than getting it from database(using SOQL query).

 

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

 

 

JoeSpecJoeSpec

Hi Hitesh,

Thannk you for taking the time to relply. much appreciated.

 

I am currently creating the test dummy test records in the test class. The actual class that is being tested does the soql calls.