You need to sign in to do that
Don't have an account?
Prabhat Singh 56
Problems with sandbox data
Hello Team,
Steps of reproduce:
I develop custom apex class, and another test class with 2 test methods. In one test method i'm quering for my company brand and geting an error: System.NullPointerException: Attempt to de-reference a null object
Class.MyTest.verifyChat2Lead: line 47, column 1.
Query I'm running is: select Id, Name from Company_Brand__c where Name='SEA'
but when I run this query from developer console i get 1 result just as i expect
Note: I created sandbox for development of custom APEX class. In testMethod I query for Custom object but get no result, but same query in developer console get 1 result.
Please help me out to solve this.
I will select the best answer.
Thanks
Prabhat
Thanks
Steps of reproduce:
I develop custom apex class, and another test class with 2 test methods. In one test method i'm quering for my company brand and geting an error: System.NullPointerException: Attempt to de-reference a null object
Class.MyTest.verifyChat2Lead: line 47, column 1.
Query I'm running is: select Id, Name from Company_Brand__c where Name='SEA'
but when I run this query from developer console i get 1 result just as i expect
Note: I created sandbox for development of custom APEX class. In testMethod I query for Custom object but get no result, but same query in developer console get 1 result.
Please help me out to solve this.
I will select the best answer.
Thanks
Prabhat
Thanks
You need to insert Company_Brand__c Object record in Order to make SOQL query. Thanks,
Amit Singh
All Answers
You need to insert Company_Brand__c Object record in Order to make SOQL query. Thanks,
Amit Singh
The best practice followed in Test cases is to Create Record before querying.
Company_Brand__c cb = new Company_Brand__c (Name='SEA');
insert cb;
please refer the following link
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_load_data.htm.
Thanks