function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDCAdmin73SFDCAdmin73 

System.NullPointerException: Attempt to de-reference a null object - PLEASE HELP

The following errors were encountered while processing an incoming email:
 
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY : SetTaskTypeToEmail: execution of BeforeInsert
 
caused by: System.NullPointerException: Attempt to de-reference a null object
 
Trigger.SetTaskTypeToEmail: line 6, column 1

I am not sure how to resolve this issue. It is a simple trigger. Please see code below. I appreciate any help. Thanks!
 
trigger SetTaskTypeToEmail on Task (before insert) {
For (Task nc:Trigger.new) {
String subject = nc.Subject;
String description = nc.Description;
If( subject != null && subject.startsWith('Email:') && description.startsWith('Additional To:')) {
nc.Type = 'Email';
}
}
}

 
Best Answer chosen by SFDCAdmin73
pconpcon
You are not checking the description to see if it s null first
 
trigger SetTaskTypeToEmail on Task (before insert) {
    for (Task nc : Trigger.new) {
        String subject = nc.Subject;
        String description = nc.Description;
        if (
                subject != null &&
                subject.startsWith('Email:') &&
                description != null &&
                description.startsWith('Additional To:')
        ) {
            nc.Type = 'Email';
        }
    }
}

All Answers

pconpcon
You are not checking the description to see if it s null first
 
trigger SetTaskTypeToEmail on Task (before insert) {
    for (Task nc : Trigger.new) {
        String subject = nc.Subject;
        String description = nc.Description;
        if (
                subject != null &&
                subject.startsWith('Email:') &&
                description != null &&
                description.startsWith('Additional To:')
        ) {
            nc.Type = 'Email';
        }
    }
}
This was selected as the best answer
SFDCAdmin73SFDCAdmin73
Thank you! That worked. 

Beth