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

How to satisfy these below lines in test class in salesforce?

How to satisfy these below lines in test class in salesforce?

Profile userProfile = [SELECT Id FROM Profile WHERE Name='System Administrator'];
            user userRole = [SELECT id, name, FROM User WHERE like '% FAWS Technical Onboarding Manager%'];
       if((userProfile.Id != UserInfo.getProfileId())||(userRole.Id != userInfo.getUserRoleId())){  

can any one suggest please?
Abu HashimAbu Hashim

Please insert a dummy user - who is not a sys admin and whose role is not FAWS Technical Onboarding manager........and use System.RunAs(dummyUser) to execute your test method logic.

Hope it helps!!
Dhanya NDhanya N
Hi Rams123,

Use below code to create UserRole and User records.
UserRole objUserRole = new UserRole(RollupDescription ='Customer Manager',  Name='Test 1'); 
        insert objUserRole;
        Profile objProfile = [SELECT Id FROM Profile WHERE Name='Other than Sys Admin '];
        User objUser = new User(
          Username = getUserNamePrefix() + '',
          Alias = 'standt',
          email = '',
          emailencodingkey = 'UTF-8',
          LastName = 'Testing',
          LanguageLocaleKey= 'en_US',
          LocaleSidKey = 'en_US',
          ProfileId = objProfile.Id,
          TimeZoneSidKey = 'America/Los_Angeles',
          UserRoleId = objUserRole.Id
       insert objUser;
Let me know if it works.