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
rmacfirmacfi 

Two newbie questions: Attempt to de-reference a null object and Priority -flag on messaging

I'm trying to make a simple notification for non-SF users that is triggered by creation or updating of a case. The first problem I ran into was a null object error on the following code:

 

trigger newCaseToCustomerService on Case (after insert, after update) {
Case myCase = trigger.new[0];
Account myAccount = myCase.Account;
User myOwner = myCase.Owner;
String CRLF = '\r\n'
String msgbody;

if(myAccount.BillingCountry == 'Denmark'){
//code here
}
}

 when SF is inserting or updating the Case, why would the Account or Owner be null since they are set in the case properties? I noticed from the other messages asking help for the null object issues that a common approach was to use SOSQL query to access related objects but I don't quite get it why is that?

 

My second question is about the Messaging -class: Does the Apex Email Class allow setting the Priority -flag on outbound, single messages?

Best Answer chosen by Admin (Salesforce Developers) 
jeffdonthemic2jeffdonthemic2

You might want to see if this blog post helps:

 

Relationship Lookup Objects in Triggers are NULL?

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

All Answers

ScoobieScoobie

Are you sure Account.billing country is populated?

 

You might want to perform a null check on it before comparing it to a literal String.

 

Also, you might want to look into the API documentation as to whether or not the mail priority can be set

jeffdonthemic2jeffdonthemic2

You might want to see if this blog post helps:

 

Relationship Lookup Objects in Triggers are NULL?

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

This was selected as the best answer
rmacfirmacfi

Thanks Jeff, that was very useful!