+ Start a Discussion
Abhinav_SFDCAbhinav_SFDC 

I get an error in my trigger

RecordNumber: execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null.: Trigger.RecordNumber: line 12, column 1



trigger RecordNumber on Record_Type__c (after insert) {
    List<Record_Type__c> rt = new List<Record_Type__c> ([Select id, name,RecordTypeid, Record_Number__c from Record_Type__c order by  Record_Number__c ]);
    String startNum = '00000';
   
    if(rt != null){
        startNum = rt.get(0).Record_Number__c ;
        startNum = startNum.substring(0,8);
        }   
    for(Record_Type__c r : Trigger.new){
        if(r.RecordTypeid == '01290000000TQfL'){
            string word1 = 'F';
             startNum = String.valueOf(Integer.valueOf(startNum) + 1);
             startNum = '00000'.substring(0, 5-startNum.length()) + startNum ;
             r.Record_Number__c = Word1 + startNum ; 
            }
            else if(r.RecordTypeid == '01290000000TQff'){
                string word2 = 'S';
                startNum = String.valueOf(Integer.valueOf(startNum) + 1);
                startNum = '00000'.substring(0, 5-startNum.length()) + startNum ;
                r.Record_Number__c = Word2 + startNum;
            }
             else if(r.RecordTypeid == '01290000000TQfa'){
                string word3 = 'T';
                startNum = String.valueOf(Integer.valueOf(startNum) + 1);
                startNum = '00000'.substring(0, 5-startNum.length()) + startNum ;
                r.Record_Number__c = Word3 + startNum;
             }
    }
}


where Record_Number__c is a text field
Eli Flores, SFDC DevEli Flores, SFDC Dev
it would be helpful if you bolded the line. With the line wraps in the forums, it's  tough to see which line you are talking about. 
Ramu_SFDCRamu_SFDC
Changes in bold text. You might also have to check if the rt result consists of record numbers for each and every record type

trigger RecordNumber on Record_Type__c (after insert) {
    List<Record_Type__c> rt = new List<Record_Type__c> ([Select id, name,RecordTypeid, Record_Number__c from Record_Type__c order by  Record_Number__c ]);
    String startNum = '00000';
  
    if(rt != null){

if(rt.get(0).record_number__c==null){

//do something

}
else{

        startNum = rt.get(0).Record_Number__c ;
        startNum = startNum.substring(0,8);

}

        }  
    for(Record_Type__c r : Trigger.new){
        if(r.RecordTypeid == '01290000000TQfL'){
            string word1 = 'F';
             startNum = String.valueOf(Integer.valueOf(startNum) + 1);
             startNum = '00000'.substring(0, 5-startNum.length()) + startNum ;
             r.Record_Number__c = Word1 + startNum ;
            }
            else if(r.RecordTypeid == '01290000000TQff'){
                string word2 = 'S';
                startNum = String.valueOf(Integer.valueOf(startNum) + 1);
                startNum = '00000'.substring(0, 5-startNum.length()) + startNum ;
                r.Record_Number__c = Word2 + startNum;
            }
             else if(r.RecordTypeid == '01290000000TQfa'){
                string word3 = 'T';
                startNum = String.valueOf(Integer.valueOf(startNum) + 1);
                startNum = '00000'.substring(0, 5-startNum.length()) + startNum ;
                r.Record_Number__c = Word3 + startNum;
             }
    }
}

Please let me know if this helped!!