Trying to deploy some changes between two sandboxes, I'm facing the following error:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, ID do tipo de registro: this ID value isn't valid for the user: 012d0000000hJHeAAM: [RecordTypeId]

This happens when inserting a record with a specific RecordTypeId in my test class. This works just fine in the development environment, but it does not work in the QA environment after deployment.

I checked if the profile had the privileges to see the profiles, and it didn't. But even after I changed them from "available" to "selected" this error persists. I'm even able to create the object manually (New > Select Record Type > Save), so I'm not sure what is wrong here.

Has this happened to someone before? I searched for this error and most of the times people just forgot to make the RTs visible, but in my case I'm with the System Administrator profile, and I checked the visibility before.

  • 1
    Can you please post a screenshot of where you believe you added the RT? I'm pretty certain you configured a similar (but separate) setting May 31, 2016 at 18:48
  • Actually, thank you for your attention to this, but I just figured out what was wrong. It is pretty stupid, however I think it is less common than just setting the visibility. I'll post the answer shortly, so this will be visible to others in the future. May 31, 2016 at 18:49

1 Answer 1


I figured out what was wrong a few minutes after posting this question! It was pretty stupid of me, because I didn't pay attention, but I believe this is a less-common issue that might confuse others:

While creating the record type for the object, I accidentally gave it an API Name that was already in use for other object. Salesforce however accepts this, because the API Name seems to be exclusive for the object, not for the organisation.

The error was caused because I tried to set a record type from another object into my object. This happened to me because I was getting the record type Id dynamically with a query:

SELECT Id, DeveloperName FROM RecordType

Always try to give different names for your objects API Names if possible, or at least filter the object in the query!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .