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
Nishad BashaNishad Basha 

restricted user test cases examples in salesforce?

How to write the restricted user test cases i nsalesforce .please give me the example of above scenario.
RAM AnisettiRAM Anisetti
Hi Basha,
you can use user restriction by below sample code....

@isTest(SeeAllData=true)
public class sampletestclass{
static testmethod void testmethod1()
{
    // create a new test user
    Profile p = [SELECT Id FROM profile WHERE Name = 'System Administrator' LIMIT 1];

    User testUser = new User(LastName = 'user 1', 
                             Username = 'user.1@sfdc.com', 
                             Email = 'usersf@gmail..com', 
                             Alias = 'test', 
                             TimeZoneSidKey = 'GMT', 
                             LocaleSidKey = 'en_GB', 
                             EmailEncodingKey = 'ISO-8859-1', 
                             ProfileId = p.Id, 
                             LanguageLocaleKey = 'en_US');     

    Test.startTest();
        System.runas(testUser)
        {
            .....Do Some Testing...
        }
    Test.stopTest();

    ..... assert the results are correct .....
}

}