You need to sign in to do that
Don't have an account?
Hermann Ouré
Error: Attempt to de-reference a null on RecordTypeId
Hello,
I am getting a System null pointer because of the RecordTypeId.
Could someone help me understand why I can't insert the record.
Thanks
List<Sub_Step__c> subStepList = new List<Sub_Step__c>(); for(List<Template_Step__c> tStepList : hcJvsTempStepMap.values()) { for(Template_Step__c tStep : tStepList ){ for(Template_Sub_Step__c temSubStepInst : tstep.Template_Sub_Steps__r){ subStepList.add(new Sub_Step__c(Name=temSubStepInst.Sub_Step_Master__r.Name, RecordTypeId = Schema.SObjectType.Sub_Step__c.getRecordTypeInfosByName().get(temSubStepInst.Sub_Step_Master__r.Name).getRecordTypeId(), Sub_Step_Number__c = temSubStepInst.Sub_Step_Number__c, Step__c =tempStepIdvsStepMap.get(tStep.id).Id, Template_Sub_Step__c = temSubStepInst.Id)); } } } if(!subStepList.isEmpty()) insert subStepList;
Because RecordType is returning null ,
you can follow below code:
Option 1: -
Option 2: -
Sample Class:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh