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();

1 Answer 1


It looks like rtInfo is null. Make sure you have "Renewals" record type on Campaign object.

  • Oh boy, that was a dumb mistake! I need the record type for an Opportunity, not a Campaign. Thanks for catching that!! Now it works!
    – John N.
    Commented Feb 12, 2015 at 21:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .