1

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);
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. Feb 12 '15 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.