You need to sign in to do that
Don't have an account?

Apply record type to record using Apex Class
Hi,
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.
if(regObj.RecordTypeID==null){
regObj.RecordTypeID = recmap1.get('Partner MPRN ROI');
I've also tried the code below but same results:
if(regObj.RecordTypeID==null){
regObj.RecordTypeID=Schema.SObjectType.site__c.getRecordTypeInfosByName().get('Partner MPRN ROI').getRecordTypeId();
}
Is there something I'm doing wrong?
Thanks in advance.
I am sure for the force.com 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 Force.com site.
Once you create Force.com 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 Force.com will have ability to see those two record type as well. But however, if you do not assign then they would not see it.