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(recordtypeid=accountrec.id, Name='TestAccount');
             insert acc;
             Contact cont = new Contact(FirstName='Test', lastName = 'Contact', phone='(888) 888-8888', AccountId=acc.id);
             insert cont;

             Group__c Group = new Group__c(Name='Group', Ownerid = me.id);
             insert Group; //**ERROR THROWN IS AT THIS LINE**
             Group_Goal__c GroupGoal = new Group_Goal__c(Name ='testGroupgoal', Group__c=Group.id);
             insert GroupGoal;
             Goals__c goal = new Goals__c(recordtypeid=goalrec.id, Ownerid = me.id, EFM_Group_Goal__c=efmGroupGoal.id, Fiscal_Year__c='FY2015');
             insert goal; //**RECORD TYPE PROVIDED IS FOR THIS RECORD** 
  • Have you hard coded a user id TestUtil.createUser() method? – highfive Aug 27 '14 at 5:58
  • No I created a user with system admin profile – Thomas Riddler Aug 27 '14 at 19:24
  • 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. – highfive Aug 28 '14 at 4:25

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.

  • 1
    Sadly, you have to use metadata API to set this up: salesforce.stackexchange.com/questions/53829/… – pcv Jul 5 '16 at 19:18
  • 5
    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. – Bow-chicawow-ers Jul 12 '17 at 21:23
  • 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. – Shane Oct 23 '20 at 0:15

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 : https://salesforce.stackexchange.com/a/166839/38191

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.