If I create a Record Type in Full Copy Sandbox and deploy to Production will the RecordTypeID persist b/w Full Copy and Prod?

I understand that if I create a Record Type in Developer/Developer Pro and deploy to Production then the RecordTypeId in Prod will change but how about Full Copy Sandboxes?

  • 2
    Not it will not. You should never rely on ids in your code. Use the describe methods to get correct recordtype ids. If formula use developername – Eric Mar 3 '17 at 20:54
  • 1
    it's only one directional: Prod => Full. Never use any hard coded Ids in the code, Workflows, formulas... – o-lexi Mar 3 '17 at 20:54

Not it will not. You should never rely on ids in your code. Use the describe methods to get correct recordtype ids. If formula use developername

  • 1
    I've ended up writing util methods that can find recordtypeId based on either label or dev name; dev name requires caching static map of recordtype dev names fetched via SOQL; dev names much less fragile than labels over time – cropredy Mar 4 '17 at 20:47
  • @cropredy - Yes. Been bit by that many times. I do not understand why SF does not add a getByDeveloperName method – Eric Mar 4 '17 at 20:49
  • me too --- it would be so obvious; just like telling you via describe the sobjectType of an sobjectField token; another gap – cropredy Mar 4 '17 at 20:57

As mentioned you should never rely on the Id, and in many cases it is also not good idea to rely on the record type label. -Label can be changed more often -If your organization use multiply languages, then using the RecordTypeInfo won't work, as it will hold the translated record type label.

Best option is to use soql query (until SF will add the record type developer name into the RecordTypeInfo).

RecordType rt = [select id, name, developername from recordType 
       where sobjectType='myobject' and developername= 'myRecordTypeDeveloperName'];

A tried and true method for getting a RecordTypeId is the following line of code.

private static final Id RECORD_TYPE_NAME_RECORD_TYPE_ID = Schema.SObjectType.<sObjectApiName>.getRecordTypeInfosByName().get('<Record Type Label>').getRecordTypeId();

I can't take credit for coming up with this one, but I did alter it slightly for clarity. Note that it uses the Label field rather than the DeveloperName field in spite of the method name. Additionally, the private, static, and final modifiers may or may not be appropriate for your application.

I first discovered it at this blog. Now I use it all the time, especially in test code.

  • known weakness to this approach is if your code is bound to a label and the point-and-click admin changes the label (or multi-language) – cropredy Mar 4 '17 at 20:37
  • @cropredy that's a very good point. I use this techinque in LOTS of test code, and I've asked (pleaded with, actually!) everyone doing declarative metadata changes to run the unit tests after making changes for these sorts of reasons. I hadn't really thought too much about the multi-language angle though... I think what we really need is a getRecordTypeInfosByName() that works against the DeveloperName! – John Thompson Mar 4 '17 at 20:50
  • use a util method getRecordTypeIdByDevName(sobjecttype sobTyp, String devName) and have method cache upon first call via soql all record types into a map. Performance penalty is small and way more robust – cropredy Mar 4 '17 at 21:00

Whenever you create Full Sandbox from Production, it will have the full copy of production with Ids. After the creation of Full Sandbox if you do anything in production it will not reflect in your full sandbox, you will need to Refresh that one.

  • While good information this does not answer the OP's question.OP is asking about deploying from sandbox to production – Eric Mar 4 '17 at 22:00

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.