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

null point exception
error: when i was trying to insert the record new with empty Trigger_Change_record_type__c filed
"""recordtypechange: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.recordtypechange: line 8, column 1""
trigger recordtypechange on Account (before insert) {
IF(Trigger.Isbefore && Trigger.IsInsert ){
Map< String,Id> typeMap = New Map< String,Id>();
for(RecordType rt: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
typeMap.put(rt.DeveloperName,rt.Id);
}
for (Account cc : trigger.new) {
if (cc.Trigger_Change_record_type__c.contains('Labs') && cc.Trigger_Change_record_type__c !=null) {
if(typeMap.containsKey('bussiness'))
cc.RecordTypeid = typeMap.get('bussiness');
}
}
}
}
Thanks
"""recordtypechange: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.recordtypechange: line 8, column 1""
trigger recordtypechange on Account (before insert) {
IF(Trigger.Isbefore && Trigger.IsInsert ){
Map< String,Id> typeMap = New Map< String,Id>();
for(RecordType rt: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
typeMap.put(rt.DeveloperName,rt.Id);
}
for (Account cc : trigger.new) {
if (cc.Trigger_Change_record_type__c.contains('Labs') && cc.Trigger_Change_record_type__c !=null) {
if(typeMap.containsKey('bussiness'))
cc.RecordTypeid = typeMap.get('bussiness');
}
}
}
}
Thanks
I recommend checking using the following in your code instead
The documentation says:
Null pointer exceptions are usually thrown by a line of code that is trying to use an object that has not been instantiated, or an object's attribute that has not been initialized.
I see you have the following query in the code. Also, it is a best practice to check for the presence of values before accessing the values. You can use the isEmpty() attribute for both list and map or use the safenavigator operator to avoid null pointer exceptions
https://help.salesforce.com/articleView?id=000327918&type=1&mode=1
Thanks @Anudeep
but errror is same