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
MikeGoelzerMikeGoelzer 

Record types in managed package in Winter '09

We have a managed package containing a custom object with three record types.  Pre-Winter '09 it worked fine; now it won't install in other orgs, and I'm hoping someone can help me understand what has changed.

Symptoms:

1.  In the dev org, doing a "Run all Tests" reports 0 failures.

2.  If I take the managed package install link to another org and install, I get a bunch of unit test failures like this:

ut_calculations_modelvalidator.SimplestTestCase()Apex Classes(01p800000008jBO)
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, record type missing for: Support Program
(ENT_2)
;


Here's the source code for this test:

Code:
    static testMethod void SimplestTestCase() 
    {
        ENT_2__Support_Program__c sp = new ENT_2__Support_Program__c( 
             Name='TestSP',
             P1__c = 'xyz'
             );
        insert sp;
    }


3.  I thought maybe Winter '09 wanted me to specify a RecordTypeId explicitly, so I tried several variations on this:

Code:
    static testMethod void SimplestTestCase() 
    {
        ENT_2__Support_Program__c sp = new ENT_2__Support_Program__c( 
             Name='TestSP',
             P1__c = 'xyz'
             );
        sp.RecordTypeId = '012300000009x0G';
        insert sp;
    }

 
Again, the dev org's "Run all Tests" has no problem with this.  (That id is a valid record type for the dev org's ENT_2__Support_Program__c object.)  But rebuilding the package and attempting an install in any other org gives this error message:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: id value not valid for the users profile: 012300000009x0GAAQ: [RecordTypeId]
(ENT_2)

Any idea what I am doing wrong?
MikeGoelzerMikeGoelzer
Side question:    why is the dev org's record type ID ('012300000009x0G') visible in the subscriber org?  I thought packaging rewrote these internally since they can't be shared across orgs.
mtbclimbermtbclimber
We're investigating this but for reference it's best to avoid hard coding IDs like this.  Using tools like eclipse or ANT to move your code around is going to require you to fix this yourself everywhere.  You are better off leveraging the Describe information in Apex and relying on the developer name of the record type, e.g.:

Code:
sp.RecordTypeId = Schema.SObjectType.ENT_2__Support_Program__2.getRecordTypeInfosByName('My Record Type').getRecordTypeId();

 If you can modify your current solution to be non-ID dependent you can work around this issue while we investigate.

Colin LoretzColin Loretz
I'm having the same issue. I thought I might be able to resolve the issue by deleting the record type (I'm no longer using more than 1) but I get a Salesforce internal server error when I try to mark the record type as inactive or when deleting it.

Error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, record type missing for: Time Bucket
(th);

 
I tried to set the recordTypeId using the method suggested:

Code:
bucket.RecordTypeId = Schema.SObjectType.TimeBucket__c.getRecordTypeInfosByName('Time Bucket').getRecordTypeId()

 However, I get an error indicating: "Method does not exist or incorrect signature: [Schema.DescribeSObjectResult].getRecordTypeInfosByName(String)"

Currently, this is the only thing that is preventing me from installing my package.

Thanks for any help you can provide.




Message Edited by Colin Loretz on 10-27-2008 11:59 AM
A_SmithA_Smith
When you say you are trying to delete a record type, are you doing this in the UI?  Do you get an error number?

Thanks,
Andrew
Colin LoretzColin Loretz
Correct, I tried to delete (and also tried to make inactive) but receive the following error screen:

An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact support@salesforce.com. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience.

Thank you again for your patience and assistance. And thanks for using Salesforce!

Error ID: 1536633561-137 (-615805889)
Colin LoretzColin Loretz
I left the record type alone because I'm still getting the error and have resolved the 'Missing Record Type' errors when installing the package.

Instead of:
Code:
bucket.RecordTypeId = Schema.SObjectType.TimeBucket__c.getRecordTypeInfosByName('Time Bucket').getRecordTypeId()

 I did used:
Code:
 RecordType rt = [Select Id, Name from RecordType where Name = 'Time Bucket' limit 1];
 bucket.RecordTypeId = rt.Id;

 The RecordType is created on the installation so no hard coding has been used.