• MattD88
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi, I'm testing a controller extension, run as a standard System Admin user, but my test class fails with the error "Read access denied for IBOS_Request__c", which I don't understand since Sysem Admin has full access to the IBOS_Request__c custom object. Thoughts?

 

TEST CLASS:

@isTest
class TestIBOSRequest
{
    static testMethod void TestIBOSRequest()
    {
        User u_adm = TestUtils.getAdminUser('adm');
        insert u_adm;
        
        ApexPages.StandardController std = new ApexPages.StandardController(ir1);
        IBOSRequestContExt irce = new IBOSRequestContExt(std);
        
        system.runAs(u_adm)
        {
            std = new ApexPages.StandardController(new IBOS_Request__c());
            irce = new IBOSRequestContExt(std);
        }
    }
}

 TestUtils Class:

Public class TestUtils
{
 private static User getTestUser(String userName, String profileName)
    {
        String profileId;
        try
        {
            profileId = [SELECT Id FROM Profile WHERE Name like: '%'+profileName+'%' limit 1].Id;
        }
        catch(Exception ex)
        {
            System.debug(ex);
            System.assert(false, 'No profile exists with name '+ profileName);
        }
        User testUser = new User();
        testUser.LastName = 'test ' + UserName;
        testUser.Alias = UserName;  
        testUser.Email = UserName+'@accruent.com';
        testUser.Username = UserName+UserName+'@test.com';
        testUser.CommunityNickname = 'a'+UserName;
        testUser.TimeZoneSidKey = 'America/New_York';
        testUser.LocaleSidKey = 'en_US';
        testUser.EmailEncodingKey = 'ISO-8859-1';
        testUser.ProfileId = profileId;
        testUser.LanguageLocaleKey = 'en_US';
        testUser.IsActive = true;
        
        return testUser;    
    }
    
    public static User getAdminUser(String adminName)
    {
        return getTestUser(adminName, 'System Administrator');
    }
}

 

Hi, I'm testing a controller extension, run as a standard System Admin user, but my test class fails with the error "Read access denied for IBOS_Request__c", which I don't understand since Sysem Admin has full access to the IBOS_Request__c custom object. Thoughts?

 

TEST CLASS:

@isTest
class TestIBOSRequest
{
    static testMethod void TestIBOSRequest()
    {
        User u_adm = TestUtils.getAdminUser('adm');
        insert u_adm;
        
        ApexPages.StandardController std = new ApexPages.StandardController(ir1);
        IBOSRequestContExt irce = new IBOSRequestContExt(std);
        
        system.runAs(u_adm)
        {
            std = new ApexPages.StandardController(new IBOS_Request__c());
            irce = new IBOSRequestContExt(std);
        }
    }
}

 TestUtils Class:

Public class TestUtils
{
 private static User getTestUser(String userName, String profileName)
    {
        String profileId;
        try
        {
            profileId = [SELECT Id FROM Profile WHERE Name like: '%'+profileName+'%' limit 1].Id;
        }
        catch(Exception ex)
        {
            System.debug(ex);
            System.assert(false, 'No profile exists with name '+ profileName);
        }
        User testUser = new User();
        testUser.LastName = 'test ' + UserName;
        testUser.Alias = UserName;  
        testUser.Email = UserName+'@accruent.com';
        testUser.Username = UserName+UserName+'@test.com';
        testUser.CommunityNickname = 'a'+UserName;
        testUser.TimeZoneSidKey = 'America/New_York';
        testUser.LocaleSidKey = 'en_US';
        testUser.EmailEncodingKey = 'ISO-8859-1';
        testUser.ProfileId = profileId;
        testUser.LanguageLocaleKey = 'en_US';
        testUser.IsActive = true;
        
        return testUser;    
    }
    
    public static User getAdminUser(String adminName)
    {
        return getTestUser(adminName, 'System Administrator');
    }
}