If we set the annotation @isTest(seeAllData = true) in the
test class then that class will have access to all data in the organization.
Example Class:
- @isTest(seeAllData = true)
- Public Class Test_AccountClass
- {
- Static testmethod void testAccountMethod1()
- {
- Account ac = [select Name from account Limit 1];
- System.assert(ac != null);
- }
- Static testmethod void testAccountMethod2()
- {
- // This method will also have access to all org data.
- }
- }
If we are using only @isTest, then it will not have access
to all org data, but it will have access to the object that are used to manage our
organization.
Object used for manage Organization:
- User
- Profile
- Organization
- AsyncApexJob
- CornTrigger
- RecordType
- Apex Class
- Apex trigger
- Apex Component
- Apex Page
Example Class:
- @isTest
- Public Class Test_AccountClass
- {
- @isTest(seeAlldata = true)
- Static testmethod void testAccountMethod1()
- {
- // this method will have access all the org data.
- Account ac = [select Name from account Limit 1];
- System.assert(ac != null);
- }
- @isTest Static testmethod void testAccountMethod2()
- {
- // This method will have access only to the above mentioned object.eg:User
- User u =[select Id,Name from User Limit 1];
- System.assert(u != null);
- }
- }
This annotation will work for the test class saved using the
salesforce API version 24.0 or latter calls. For earlier version i.e. 23.0 or earlier
continues to have access to all data in the organization and its data access is
unchanged.
No comments:
Post a Comment