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....

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 = '', 
                             Email = '', 
                             Alias = 'test', 
                             TimeZoneSidKey = 'GMT', 
                             LocaleSidKey = 'en_GB', 
                             EmailEncodingKey = 'ISO-8859-1', 
                             ProfileId = p.Id, 
                             LanguageLocaleKey = 'en_US');     

            .....Do Some Testing...

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