You need to sign in to do that
Don't have an account?
Armoury
Null Pointer Exception
Hi.. I just came noticed an unknown behavior (to me) in Apex.
I used the below query to pull the data from Case Object.
So how come the second statement to fetch the postal code from Account doesnt throw Null pointer exception but still prints as null. Is this because of the way I query the record??
I used the below query to pull the data from Case Object.
Select Id, Account.PersonMailingPostalCode from CaseAnd the below are my System.debug statements..
System.debug('********** Account = ' + caseList[0].Account); System.debug('********** PersonMailingPostalCode = ' + caseList[0].Account.PersonMailingPostalCode);The debug logs shows as below without any exception..
'********** Account = null *********** PersonMailingPostalCode = nullwhich means that the account is not associated to the case yet. So the caseList[0].Account is null
So how come the second statement to fetch the postal code from Account doesnt throw Null pointer exception but still prints as null. Is this because of the way I query the record??
Temoc - I just found out this in the apex documentation.
I think the above statment is true not only for traversing the relationships but also for all the objects which SOQL returns the result.
I tried the below code.
But I do get the exception when i assigned the account to the object like below
All Answers
https://developer.salesforce.com/page/Introduction_to_the_Force.com_Web_Services_Connector
What I have below is just an idea of what I think is going on and should not be taken as the real Salesforce implementation:
Temoc - I just found out this in the apex documentation.
I think the above statment is true not only for traversing the relationships but also for all the objects which SOQL returns the result.
I tried the below code.
But I do get the exception when i assigned the account to the object like below
I should have mentioned in my first post. To get the additional fields (ie AccountId) you will need to add those to your query. Any fields on records not in the trigger will need to be queried for.
You only get the current records direct fields for "free". Any other record fields on other similar object records or related (parent, child) records will need to be queried for.
-derhyk