Find your content:

Search form

You are here

On upgrade to Salesforce 26.0 Api, Test Case is not pulling any data in Console

 
Share

I am running a test case , I have upgraded my Salesforce Sandbox to latest version Api (26.0). Running SOQL individually give me results but while using Console I ran in error where SOQL comes out with 'Zero' results.

I would like to know, if we upgrade to new version, there could be possibility that I cannot pull the data from the Console, I believe there should be some annotation or some workaround that permit console (using new Api) to access the data.

Please advice, you can correct me if I am wrong

Login_Credentials__c enterprise = [
    SELECT Id,Name, RecordTypeId,  Account__c, Contact__c, Product__c, User_name__c, 
        Password__c,Item__c,Contact__r.Email 
    FROM Login_Credentials__c 
    WHERE Item__c =: 'ENTERPRISE' LIMIT 1
];

SQOL query comes with Zero results in Console


Attribution to: Harshit Pandey

Possible Suggestion/Solution #1

Using the dynamic reference =: with a string literal 'ENTERPRISE' won't work, I believe. Use Item__c = 'ENTERPRISE'. Also, are you using double-underscores?

Also, don't forget that in newer API versions, test code doesn't see existing data, and must create its own data. So a query in the console and in test code will effectively be in totally different orgs (data-wise).

SOQL is backwards-compatible, so you won't lose anything in the query when your org goes to a new version or you run Apex in a new API version. I can't see any other reasons why your query will return fewer results in the console than in your test data.


Attribution to: DavidSchach

Possible Suggestion/Solution #2

Please create Test Data in your Test Class then Query the same for the Update .In test class its a best practice to not to use data from database.


Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #3

It sounds like maybe you haven't refreshed your sandbox for a while. A change was made in API version 24.0 to isolate data by default when running unit tests. It is possible to still access the data records, if you must, by altering the annotation to @IsTest(SeeAllData=true). The isolation makes test code a bit easier to write because you do not have to worry about keeping the existing records from interfering with your test case.

A best practice for apex testing is to create all data used within the test method (or load it with the new loadData method). Some reasons for this are to eliminate org dependency when moving the code from sandbox to sandbox to ... to production (you would have to also move the data for the test to pass) and when you know what the input is you can know what the expected output is (difficult to determine with unknown input).

Try creating a new Login_Credentials__c record for the assignment to enterprise instead making a query for it -

Login_Credentials__c enterprise = new Login_Credentials__c(
    Name='xyz', RecordTypeId='123...', etc);

This is not so much part of the solution now, but because of the way you wrote the query assignment (I used to do the same thing), I think you should look over the question Handling a Query Zero Results for some tips when querying for only 1 record. It changed me around.


Attribution to: zjeh
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4502

My Block Status

My Block Content