Invalid Cross Reference Key : Record Type ID value isn't valid for User: 012v00000008f4nuBB

  • I am having some issues. The below is a code snipet of my test class. The class complies and produces 96% of coverage with no errors. When deploying in production it throws the above error.

    Salesforce says the error is on the first bolded line. However the recordtypeid it throws at me is a recordtype for the second bolded line: which in itself is a legit recordtype.

     User me = TestUtil.createUser();     
            RecordType accountrec = [select id from RecordType where sObjecttype ='Account' and DeveloperName='prop'];
             RecordType opprec = [select id from RecordType where sObjecttype ='Opportunity' and DeveloperName='full'];
             RecordType goalrec = [select id from RecordType where sObjecttype ='Goals__c' and DeveloperName='Manager'];
                 Account acc = new Account(, Name='TestAccount');
                 insert acc;
                 Contact cont = new Contact(FirstName='Test', lastName = 'Contact', phone='(888) 888-8888',;
                 insert cont;
                 Group__c Group = new Group__c(Name='Group', Ownerid =;
                 insert Group; //**ERROR THROWN IS AT THIS LINE**
                 Group_Goal__c GroupGoal = new Group_Goal__c(Name ='testGroupgoal',;
                 insert GroupGoal;
                 Goals__c goal = new Goals__c(, Ownerid =,, Fiscal_Year__c='FY2015');
                 insert goal; //**RECORD TYPE PROVIDED IS FOR THIS RECORD** 

    Have you hard coded a user id `TestUtil.createUser()` method?

    No I created a user with system admin profile

    Since you are getting the error while deploying I suspect there is some `Id` has been hardcoded some where. Just have a look at all the support classes, test classes, etc.

  • Profiles have record type settings. This error means that the user has a profile for which that record type is not enabled. You need to make sure the profile you're using has access to the desired record type, or that the value is being set in a "without sharing" class.

    Note to others: this same error message is returned when you set a RecordTypeId field to a RecordType from a different sObject. You might get this error message if your RecordType query does not filter by sObjectType. The DeveloperName is unique per sObject, but not system-wide.

    Shouldn't Permission Sets override this? In other words, say Standard User Profile doesn't have that Record Type assigned, but you give the user a permset which does have that record type.

  • The test user that you are creating, probably does not have the sufficient rights to access that object. If you did not have any issues in Sandbox, then add the required profiles to the change set and then deploy them.

  • Check whether Profile of the newly created user has access to the record types being referred in your code as shown below.

    enter image description here

  • Have you tried this?

    Go to:

    Setup > Administer > Manage Users > Profiles > System Admin > Object Settings > [All relevant Object Names] > Tick the appropriate "Assigned Record Types"

    As answered in :

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM