+ Start a Discussion
SittamSittam 

execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.emailergebnis: line 6, column 1

Hey guys,

im trying to setup an apex trigger, which triggers on an email to sf and sets a specific field to a specific value. I already accomplished that. Here is the code:
trigger emailergebnis on Task (before Insert) {

    for(Task tNew : trigger.new){
        
        /*Check if the Task is being created as result of Email to Task*/
        if(!String.isBlank(tNew.Subject) && tNew.Subject.toLowerCase().startsWith('e-mail:')) {

             tNew.Ergebnis_Aktivit_t__c = 'Email / SMS / Whatsapp';  }}}
But now I am trying to add that this only happens on a specific record type, but i get error message: execution of BeforeInsert  caused by: System.NullPointerException: Attempt to de-reference a null object  Trigger.emailergebnis: line 6, column 1

Here is the new Code:
trigger emailergebnis on Task (before Insert) {

    for(Task tNew : trigger.new){
        
        /*Check if the Task is being created as result of Email to Task*/
        if(!String.isBlank(tNew.Subject) && tNew.Subject.toLowerCase().startsWith('e-mail:')&& tNew.RecordType.DeveloperName.equals('Partner')) {

             tNew.Ergebnis_Aktivit_t__c = 'Email / SMS / Whatsapp'; }}}

SittamSittam

So something has to be wrong with this part:

tNew.RecordType.DeveloperName.equals('Partner')

Prashant Pandey07Prashant Pandey07
Hi Sittam,

Your recordtype not getting the value that's why your are getting error..

You can get the record type like this..
String r= Schema.SObjectType.Account.getRecordTypeInfosByName().get('Partner').getDeveloperName();

--
Thanks,
Prashant
SittamSittam
hey thanks for your answer,

where do i put that line of code?