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

Apply record type to record using Apex Class


We appear to be having an issue on our Salesforce portal - it looks like when we attempt to register a customer as 'Renewal' there is no record type assigned to the record.  So when we press the save button we get an error message saying about a Bad Value for Record Type with the ID being null.

In order to resolve this issue I want to add a condition so that if the user selects Renewal then to apply a particular record type or if the recordtypeID is blank then apply a record type.

Does anyone know how to do this?

I've tried some code but when I do I get the attempt to de-reference a null object error on the visualforce page.

This is what I have currently in the apex class which is causing the issue.

regObj.RecordTypeID = recmap1.get('Partner MPRN ROI');

I've also tried the code below but same results:

                    regObj.RecordTypeID=Schema.SObjectType.site__c.getRecordTypeInfosByName().get('Partner MPRN ROI').getRecordTypeId();

Is there something I'm doing wrong?

Thanks in advance.


I think for the portal or site users there is a different profile and you should make Record Type available there for them.

I am sure for the site users that salesforce creates a seperate profile for them and you need to assign permission on that profile in order for them to get an access.

e.g.,, let's say Account has two record types Record Type - 1 and Record Type - 2.
Now, you want to show all of your accout to the world by creating site.
Once you create site, salesforce will cerate a seperate Profile for them and then you need to assign Account Object level acceess + Record Type access etc.. in to that profile. Once assigned, all users who sees the Account on will have ability to see those two record type as well. But however, if you do not assign then they would not see it.