+ Start a Discussion
John NeilanJohn Neilan 

Trigger Error - Attempt to De-Reference Null Object

Hello,

I'm trying to create a trigger class that will clone an Opportunity that is of a certain record type and reaches a Stage that contains Close Won.  Everything saves fine, but when I try to close out an Opp I get the error message:

System.NullPointerException: Attempt to de-reference a null object: Class.ClassRenewalOppClone.cloneOpp: line 8, column 1

Does anyone know why I might be getting this?

Trigger Class:
public class ClassRenewalOppClone {
        
        public void cloneOpp(List<Opportunity> cloneOpp){
    
        String recordTypeName = 'Renewals';
        Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Campaign.getRecordTypeInfosByName();
        Schema.RecordTypeInfo rtInfo =  rtMapByName.get(recordTypeName);
        id recType = rtInfo.getRecordTypeId();
    
            
            FOR(Opportunity opp1 : cloneOpp){
                IF(opp1.StageName.contains('Closed Won') && opp1.RecordTypeId == recType){
Before Update Trigger:
        
ClassRenewalOppClone updater4 = new ClassRenewalOppClone();
            updater4.cloneOpp(Trigger.new);


Best Answer chosen by John Neilan
John NeilanJohn Neilan
Thanks.  I actually found that my error was that it was looking at the Campaign object for the record type and not the Opportunity object (line 6).  I fixed that and it now works.

All Answers

HawkedHawked

Check if you have a record type named Renewals on opportunity object, Go to Setup--> Customize--> Opportunities --> record types
John NeilanJohn Neilan
Thanks.  I actually found that my error was that it was looking at the Campaign object for the record type and not the Opportunity object (line 6).  I fixed that and it now works.
This was selected as the best answer