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
donrdonr 

Select not returning values

Below is a simple test I have written, all it suppose to do is a select an account and upsert it. No matter what I try I cannot get the select statement to any return values. I've opened it up to accept anything but it seems no matter what I do and not matter what object I try no records are returned. 

 

I'm at a loss to why no values are returned when I am certain there are many rows. I am logged in as Platform sys admin when running these tests. I'm using force.com development environment. 

 

Is there a limit or something in SF I'm running into or ??

 

Help me.. Will Robinson

 

public class ShareTriggerTestMethod 
  {
    static testMethod void MySharingTest()
      {    
         
        //get a acount to update

        account acc = [select Id, name, comment__c from account limit 1];

     

         acc.comment__c = 'test';
         
         // upsert data causing the trigger to fire.
         Test.startTest();
           upsert acc;
         Test.stopTest();
      }
  }

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

Begining with API 25 or so, your test methods do not have access to existing data unless you use the SEEALLDATA=true

 

It is best practice to create any records you are using in the test any way so, create and account and insert it, then your query will return a result.

All Answers

Starz26Starz26

Begining with API 25 or so, your test methods do not have access to existing data unless you use the SEEALLDATA=true

 

It is best practice to create any records you are using in the test any way so, create and account and insert it, then your query will return a result.

This was selected as the best answer
SamuelDeRyckeSamuelDeRycke

Yep, what Starz26 said. but it's since api 24.  Try to minimize the dependencies your test code has to records or configuration, ifnot, your tests can start failing when deleting/editing records of chaning configuration. Thats not a situation you want to run into.

donrdonr

Thanks much the info info!

 

The reason I was using existing data was I'm building a trigger to share salesforce to salesforce data and my test method was failing. I was told you had to use existing records that were already shared. However, I recently read sharing must be prod to prod or sandbox to sandbox. 

 

Anyway thats a different issue, thanks for the assistance and information it's really appreciated...