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
QotDQotD 

Test Classes Failed after creating Managed-Beta Package

I created a Managed-Beta Package and all my test classes failed after I added the Namespace prefix. They worked before and it is all still on the same org.
Here is the error I am getting
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]
And here is one of the test classes
@isTest
public class Dog_Forms_Evaluations_Notes_Test {
    private static testmethod void behaviorMgt(){

        User u = [select id from user where profile.name like '%System Administrator%' and isactive = true limit 1 ];
         
        List<RecordType> brTypes = [SELECT Name,Id FROM RecordType WHERE sObjectType = 'Dog_Forms_Evaluations_Notes__c' AND isActive=true];    
        List<RecordType> rTypes = [SELECT Name,Id FROM RecordType WHERE sObjectType = 'Dog__c' AND isActive=true];    

        Map<String,String> bRecordTypes = new Map<String,String>{};
        Map<String,String> DogRecordTypes = new Map<String,String>{};
        for(RecordType brt: brTypes)
        {
            bRecordTypes.put(brt.Name,brt.Id);
        }  
        for(RecordType rt: rTypes)
        {
            DogRecordTypes.put(rt.Name,rt.Id);
        }  
        System.RunAs(u){
            Dog__c d = new Dog__c(
                Name = 'TestDog', 
                RecordTypeId = DogRecordTypes.get('In Training'),
                OwnerId = u.id
            );
            insert d;
            
            Dog_Forms_Evaluations_Notes__c f = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Month(s)'
            );
            insert f;     

            Dog_Forms_Evaluations_Notes__c f2 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Week(s)'
            );
            insert f2; 
            
            Dog_Forms_Evaluations_Notes__c f3 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Day(s)'
            );
            insert f3;   
            
            Integer getTask = [SELECT Count() FROM Task WHERE Subject LIKE 'Behavior Management Follow Up for%' AND WhatId =: d.Id];
            System.assertEquals(3,getTask);      
            
          // error code test && bulk test      
          // 
          List<Dog_Forms_Evaluations_Notes__c> dogErrors = new List<Dog_Forms_Evaluations_Notes__c>();
            for (Integer i=0;i<200;i++) {
    
                Dog_Forms_Evaluations_Notes__c f4 = new Dog_Forms_Evaluations_Notes__c(
                RecordTypeId = bRecordTypes.get('Behavior Issue Management'),
                Dog__c = d.id,
                Date__c = system.today(),
                Describe_Incident_or_Behavior_Issue__c = 'Test',
                Behavior_Management_Plan__c = 'Test',
                Check_Effectiveness_In_Number__c = 2,
                Check_Effectiveness_In__c = 'Wrong'
            );
                dogErrors.add(f4);
    
            }      
            try{
                insert dogErrors;
            }catch(Exception e) {
                System.Assert(e.getMessage().contains('Picklist value for field Check Effectiveness In'));
            }
            
              
    	}
    }
}

 
QotDQotD
I figured it out. Had to create another class so that the sObject name wasn't hard coded. 
Link to fix: lhttp://salesforce.stackexchange.com/questions/11968/what-would-be-the-best-approach-to-get-the-recordtype-id