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
JoThomasJoThomas 

Salesforce Production Deployment Test Class Error out.Unable to access record type

As we all know for production deployment , Test classes will be automatically running , right !!! . We have issue with that . Half of our test classes are failing because of access issues .

Items to note :
  • 1)in Our test classes it is not using any database data .ie SeeAllData =false
  • 2)First deployment to Production . No recordtypes available
  • 3) we are pushing admin profile in the package which have access to all the records types present .
Issue: Test class is using below statement for creating dummy record with specific record type Schema.SObjectType.Contact.getRecordTypeInfosByName().get('XXXXX').getRecordTypeId();

Actual Issue : As our production doesnt have any recordtype test class is failing saying it unable to find the record type .

Now million dollar question : How we can over come this issue . it is really blocking our production deployment
Best Answer chosen by JoThomas
JoThomasJoThomas
Hi All, 

we able to solve this issue, as it is new environemnt , system admin doesnt have any recordtype access . once we provided the recordtype access to systemadmin we able to complete the deployment on time . 

Note: we deploy all the components in single deployment ( Metedata and code ) around 8500 components .

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please deploy recordType first in production then try to deploy code. Please follow below deployment order

Step 1) Deploy all metadata first (Object ,field and record Type)
Step 2) Then deploy code.
Sven FrancornelSven Francornel
Is the new Record Type part of the package that you are trying to deploy to production? If not, could you add it to the package and try to deploy again?
Mubeen QawiMubeen Qawi
Joseph, It would be helpful to provide more context.

Without actual error and based on the information you provided, some of my thoughts below:
Check for the following:
 - If the record type for the Contact sObject is in existence. Sometimes, it get deleted.
 - In the affect test class, check for Running Context User and assigned Profile. Including a Profile as a part of change set doesn't have anything to do with running of the Test Class.
 - Finally, if you are stuck and running against the time,  hard cord the record type id (disclaimer - not a best practice). And sure that the context user/profile has access to record type in subject.

Hope it helps

Mubeen Qawi
 
JoThomasJoThomas
Thanks all for the reply , currently , we are doing our deployment using Bitbucket(devops) .it currently having only one package having all the metadata items . which includes records types and even profile . 
@Mubeen --Our producton is empty , no record type is available 
@sven -- it is included in the package , plus admin profile  which is part of package having access to those records .but still it is throwing error 
@Amit -- Yes, Splitting is only option .but our objects have button and Vf pages which leads to Classes. Menaing , it leads to lots of confusion 
Pramodh KumarPramodh Kumar
Without deploying the metadata, your problem will not be solved. 
When deploying the system will validate against the metadata, If it s new environment, make two packages one for the metadata and other packages for features like apex classes, triggers etc.

This is the only available option to deploy to your code.

Thanks
Pramodh
 
JoThomasJoThomas
Hi All, 

we able to solve this issue, as it is new environemnt , system admin doesnt have any recordtype access . once we provided the recordtype access to systemadmin we able to complete the deployment on time . 

Note: we deploy all the components in single deployment ( Metedata and code ) around 8500 components .
This was selected as the best answer