You need to sign in to do that
Don't have an account?
![divya1234 divya1234](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
caused an unexpected exception, contact your administrator: NewtestCaseRecord: execution of AfterInsert caused by: System.NullPointerExcept em.NullPointerException: NewCaseRecord: execution of AfterInsert caused by: System.NullPointerException: Attempt
I am trying to create new testcase record for some case recordtype which is matching particular condition.i configured everything whch is need in the code like recordtype name status ,recordtype id ispriavte in in my custom setting , now i m trying tocreate a record using trigger .but while creating a record i am geting "Apex trigger NewtestCaseRecord caused an unexpected exception, contact your administrator: NewtestCaseRecord: execution of AfterInsert caused by: System.NullPointerException: NewCaseRecord: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: ()" can someone please help me to find wht i am missing in my triger
trigger NewTestCaseRecord on Case (after insert,before update, after update) { if(!UserValidation.ValidationAccess()) { system.debug('Chatter_helper.getIstestCaseCreated()' + Chatter_helper.getIstestCaseCreated()); if (!Chatter_helper.getIstestCaseCreated() ) { Map<string,string> caseRecordTypeMap = new Map<string,string>(); set<string> caseRecordTypeSet = new set<string>(); string rec_type; CaseRecordTypeClass RecordtypeCS = new CaseRecordTypeClass(); RecordtypeCS.CaseFetchRecordtypes(); Map<string, test_Settings__c> allRecordTypeMap = CaseRecordTypeClass.CaseRecordtypeMap; system.debug('allRecordTypeMap :NewServicenetrecord:' + allRecordTypeMap); for(test_Settings__c RT : allRecordTypeMap.values()){ if(RT.SobjectType__c == 'case'){ if(RT.Name == 'Request1' || RT.Name == 'req2' || RT.Name == 'req3' || RT.Name == 'req4') { caseRecordTypeMap.put(RT.Name, RT.RecordtypeId__c.substring(0,15)); caseRecordTypeSet.add(RT.RecordtypeId__c.substring(0,15)); } } } system.debug('caseRecordTypeMap : ' + caseRecordTypeMap); system.debug('caseRecordTypeSet : ' + caseRecordTypeSet); List<test_Case__c > testCaseList = new List<test_Case__c >(); List<Case> caselist = new List<Case>(); for(Case c: trigger.new){ rec_type=c.RecordTypeId; if( caseRecordTypeSet.contains(rec_type.substring(0,15)) && C.Status == 'CaseRecordType__c.Status__c' && c.AD_Private__c == true) { caselist.add(c); } } /* for(Case c: trigger.new){ IF(Case.RecordtypeId = test_Settings__c.RecordtypeId__c){ rec_type=c.RecordTypeId; //if( caseRecordTypeSet.contains(rec_type.substring(0,15))) { If(C.Status == 'test_Settings__c.Status__c' && c.AD_Private__c == false){ test_Case__c testCase = new test_Case__c(); testCase.Case = Case.ID; testCase.SendEmail = true; testCase.NotificationType = test_Settings__c.NotificationType; testCaseLISt.add(testCase); caselist.add(c); } } }*/ // system.debug('***caselist'+caselist.size()); if(caselist.size()>0) { for(case c : caselist){ rec_type=c.RecordTypeId; test_Settings__c CRT = new test_Settings__c(); test_Case__c testCase = new test_Case__c(); if(CRT.Send_Email_to_OSJ__c == true){ rec_type=c.RecordTypeId; testCase.Case__c = c.ID; testCase.Send_Email__c = true; testCase.Notification_Type__c = CRT.Notification_Type__c; testCaseLISt.add(testCase); } else{ rec_type=c.RecordTypeId; testCase.Case__c = C.ID; testCase.Send_Email__c = false; testCase.Notification_Type__c = CRT.Notification_Type__c; testCaseLISt.add(testCase); } } }
![Egor Gerasimenko 9 Egor Gerasimenko 9](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Check system logs to find out which line is causing the exception. Somewhere you are doing a null reference, but that's a lot of code to go through to figure out where. The logs will tell you exactly which line is causing it.