You need to sign in to do that
Don't have an account?

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?
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
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
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
Thanks Jeff, that was very useful!