• Bryan Gordon
  • NEWBIE
  • 20 Points
  • Member since 2014
  • Data Analyst
  • The Dallas Foundation


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I have a trigger on a custom object (before insert and before update) that is looking at the Account object.  The custom object GWU40__c has an email address which is looking at the Account.PersonEmail (person-enabled accounts in Salesforce).

Every time it executes this line:
g.Nominee_Profile_ID__c = AccountMapNominees.get(g.Nominee_Email__c).FIMS_ID__c

it tells me de-referencing a null object (i'm sure it's becasue there isn't an Account with that email address).  
How can I check to see if the Map.get() is returning null?   

-------------------------------
trigger X_GWU40_LookupProfileIDs on GWU40__c (before insert,before update) {
    Set<String> noms = new Set<String>(); //Dedupe the email addresses in case of multiple nominations for the same person (email address)
    
    for(GWU40__c recordsToProcess : Trigger.New)
    {
        if(recordsToProcess.Nominee_EMail__c != null) {
            noms.add(recordsToProcess.Nominee_Email__c);
        }
        
    }
    
    Map<String,Account> AccountMapNominees = New Map<String,Account>();
        For(Account a : [SELECT PersonEmail,Name,FIMS_ID__c from Account where PersonEmail IN: noms]){
            AccountMapNominees.put(a.PersonEmail,a);
        }
      IF((!AccountMapNominees.isEmpty()) && (AccountMapNominees.size() > 0)){

      FOR(GWU40__c g : Trigger.New)
      {
          if (g.Nominee_Email__c != null)
          {            
             g.Nominee_Profile_ID__c = AccountMapNominees.get(g.Nominee_Email__c).FIMS_ID__c;                                 
          }
      }
     } //if 
   
}

------------------------------------
I have a trigger that fires off when a field called "FIMS_FundID__c" is updated.  code looks like this:


trigger Z_TDF_TaskOnUpdate on Task (after update) {
    if(trigger.isUpdate){
        for(Task t : Trigger.new){
            Task oldTask = Trigger.oldMap.get(t.Id);
            if ( t.FIMS_FundID__c != oldTask.FIMS_FundID__C)
            {
              String userEmail = 'bgordon@dallasfoundation.org';
              Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
              String[] tmp = new String[]{'bgordon@dallasfoundation.org'} ;
              mail.setToAddresses(tmp); 
              mail.setInReplyTo('noreply@dallasfoundation.org');
              mail.setSenderDisplayName('Salesforce CRM Notification');
              mail.setSubject('ID CHANGED for record ' + t.FIMS_ID__c ); 
              String body = 'The Fund ID changed on activity record # ' + t.FIMS_ID__c + ' from ' + oldTask.FIMS_ID__c + ' to ' + t.FIMS_ID__c + '.'; 
              mail.setPlainTextBody(body); 
              Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail});
            }
        }
    }    
}


When the field is updated, the email is sent, but the values are "null"

So the subject reads: ID CHANGED for record null
and the body of the email reads:  The Fund ID changed on activity record # null from null to null.

does anyone know why the null values appear?  If I use "t.Id" or oldTask.Id, they show up in the email correctly, but none of the other fields do.

 
I have a trigger on a custom object (before insert and before update) that is looking at the Account object.  The custom object GWU40__c has an email address which is looking at the Account.PersonEmail (person-enabled accounts in Salesforce).

Every time it executes this line:
g.Nominee_Profile_ID__c = AccountMapNominees.get(g.Nominee_Email__c).FIMS_ID__c

it tells me de-referencing a null object (i'm sure it's becasue there isn't an Account with that email address).  
How can I check to see if the Map.get() is returning null?   

-------------------------------
trigger X_GWU40_LookupProfileIDs on GWU40__c (before insert,before update) {
    Set<String> noms = new Set<String>(); //Dedupe the email addresses in case of multiple nominations for the same person (email address)
    
    for(GWU40__c recordsToProcess : Trigger.New)
    {
        if(recordsToProcess.Nominee_EMail__c != null) {
            noms.add(recordsToProcess.Nominee_Email__c);
        }
        
    }
    
    Map<String,Account> AccountMapNominees = New Map<String,Account>();
        For(Account a : [SELECT PersonEmail,Name,FIMS_ID__c from Account where PersonEmail IN: noms]){
            AccountMapNominees.put(a.PersonEmail,a);
        }
      IF((!AccountMapNominees.isEmpty()) && (AccountMapNominees.size() > 0)){

      FOR(GWU40__c g : Trigger.New)
      {
          if (g.Nominee_Email__c != null)
          {            
             g.Nominee_Profile_ID__c = AccountMapNominees.get(g.Nominee_Email__c).FIMS_ID__c;                                 
          }
      }
     } //if 
   
}

------------------------------------
I have a trigger that fires off when a field called "FIMS_FundID__c" is updated.  code looks like this:


trigger Z_TDF_TaskOnUpdate on Task (after update) {
    if(trigger.isUpdate){
        for(Task t : Trigger.new){
            Task oldTask = Trigger.oldMap.get(t.Id);
            if ( t.FIMS_FundID__c != oldTask.FIMS_FundID__C)
            {
              String userEmail = 'bgordon@dallasfoundation.org';
              Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
              String[] tmp = new String[]{'bgordon@dallasfoundation.org'} ;
              mail.setToAddresses(tmp); 
              mail.setInReplyTo('noreply@dallasfoundation.org');
              mail.setSenderDisplayName('Salesforce CRM Notification');
              mail.setSubject('ID CHANGED for record ' + t.FIMS_ID__c ); 
              String body = 'The Fund ID changed on activity record # ' + t.FIMS_ID__c + ' from ' + oldTask.FIMS_ID__c + ' to ' + t.FIMS_ID__c + '.'; 
              mail.setPlainTextBody(body); 
              Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail});
            }
        }
    }    
}


When the field is updated, the email is sent, but the values are "null"

So the subject reads: ID CHANGED for record null
and the body of the email reads:  The Fund ID changed on activity record # null from null to null.

does anyone know why the null values appear?  If I use "t.Id" or oldTask.Id, they show up in the email correctly, but none of the other fields do.