SAFE HARBOR: best to double check if this works on a Sandbox, before executing this on your production data. I have just written this here without explicitly testing
What you will have to do is change your profile settings to include the --master-- record type in order to "see" it, you will also have to do this for every profile on your org, to make sure your Record Type isn't being used by other profiles, else you won't be able to delete the record type
- Go to Your Name -> Setup
- Administration Setup -> Manage Users -> Profiles
- Select your profile, and go to Record Type Settings
- Choose your SObject (Product2) -> Edit
- In order to include --Master--, you will have to remove the other Record Types
- Save
- Repeat for every profile in your org
Side note:
I don't think it is actually necessary to move records to another recordtype with code, try going to your SObject -> Record Types -> Select your record type -> Deactivate -> And now try deleting it, you should get the option to move all the records with that recordtype to another.
If you would need to do it with code, this is probably the easiest way.
Now you have multiple things you can do, but either way you must update all your SObjects (Product2) with that recordtype in your database and put the RecordTypeId on (blank), you can do this via the dataloader, by first exporting, then clearing all the values in RecordTypeId, and doing an update.
But I find the easiest way to achieve this is by Apex, more precisely executing Anonymous Apex via the Eclipse IDE
- Start Eclipse
- Add your project
- Next look for the View Execute Anonymous, it can be somewhere on your screen but if you can't find it go for: Window -> Show View -> Execute Anonymous
- Make sure you select the correct Project when executing.
- Execute the following code:
List products = new List([SELECT Id, RecordTypeId FROM Product2 WHERE RecordTypeId != NULL]);
for(Product2 p : products)
{
p.RecordTypeId = NULL;
}
update products;
Now you'll need to deactivate your recordtype, and then delete it
The closest I can get is the default record type for the current user:
//find all Opportunity record types
List<Schema.RecordTypeInfo> infos = Schema.SObjectType.Opportunity.RecordTypeInfos;
Id defaultRecordTypeId;
//check each one
for (Schema.RecordTypeInfo info : infos) {
if (info.DefaultRecordTypeMapping) {
defaultRecordTypeId = info.RecordTypeId;
}
}
//here is the default Opportunity RecordType Id for the current user
System.debug(defaultRecordTypeId);
Best Answer
This should be possible. I've modified the example from the doc here just slightly. Assume yourRecordTypeId is populated with the right Id.
I would use some lines in an apex controller to get the available Record Type Ids via a SOQL query together with their Names and possibly show that in a custom picklist dynamically. Or use any logic in JavaScript.
Be careful while deploying the code to different Org: Record Type Ids might be different even if the Name is the same.