You need to sign in to do that
Don't have an account?
Bryan Gordon
Map.get returning Null object
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
}
------------------------------------
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
}
------------------------------------
Let me know if this helps.
All Answers
Let me know if this helps.