2

Using the SObjectDescribe mechanism to find record types I find that the Default Record Type ID for my SObject is the Master Record Type ID (012000000000000AAA). If I try to insert a row with this record type ID, even in a without sharing inner class, I receive the following exception:

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: 012000000000000AAA: [RecordTypeId]

There are two other record types. According to the SObjectDescribe information they are not available to the current user. My debug based on the SObjectDescribe information has the following:

Record Type Simple with id 012w0000000AgcTAAS FORBIDDEN
Record Type Chunked with id 012w0000000AgcUAAS FORBIDDEN
Record Type Master with id 012000000000000AAA AVAILABLE

Seems I can't set null either. I wonder if I don't set anything whether it would work, but I'd like to choose one of the custom ones by name and fall back to the default if I can't find the name I want or am not given a name. I've yet to write a test to see if I can set by name.

9
  • Is there a Detail Page assigned to a profile for the Default Record Type ID?
    – crmprogdev
    Commented Nov 12, 2014 at 16:34
  • Unlikely. The code I'm deploying doesn't have Profiles in it, so nothing would be assigned. Though I'll be running in a situation where the end user may not have anything assigned for this object and may not even be able to see this object. Our app is working on that user's behalf and needs to maintain its own data, even if the user themselves cannot see it. Commented Nov 12, 2014 at 16:56
  • You may need to create permission sets that make the other Record Types available to users. As this is a managed package, you might also want to consider using the Developer Name for the Record Type instead of it's Record Type ID.
    – crmprogdev
    Commented Nov 12, 2014 at 17:09
  • Can I do that directly? I'd only found RecordTypeId on the object, but if I can read and write RecordTypeName directly it would save some bother. Commented Nov 12, 2014 at 17:23
  • Yes you can. Here's just some of what you can query on RecordType: SELECT DeveloperName, Id, Name, BusinessProcessId, CreatedById, CreatedDate, Description, IsActive, NamespacePrefix, SobjectType FROM RecordType.
    – crmprogdev
    Commented Nov 12, 2014 at 17:36

0

You must log in to answer this question.

Browse other questions tagged .