You need to sign in to do that
Don't have an account?
anuragsinghns
Attempt to dereference a null object error
Hi Guys,
I get Attempt to dereference a null object error with the system.debug below but if I comment it out the case gets created and also an account gets associated with it!Could you help me resolve this issue
//associating a account to the case
caseAccountPresent.accountId=accountUniqueIdMap.get(caseUniqueIdMap.get(caseAccountPresent)).Id;
//debug of the same
system.debug('the Account'+accountUniqueIdMap.get(caseUniqueIdMap.get(caseAccountPresent)).Id);
I get Attempt to dereference a null object error with the system.debug below but if I comment it out the case gets created and also an account gets associated with it!Could you help me resolve this issue
//associating a account to the case
caseAccountPresent.accountId=accountUniqueIdMap.get(caseUniqueIdMap.get(caseAccountPresent)).Id;
//debug of the same
system.debug('the Account'+accountUniqueIdMap.get(caseUniqueIdMap.get(caseAccountPresent)).Id);
Looks like you are using an SOBject as a key in your map. thats not really recommended. And your code is changing that SOBject in the line
caseAccountPresent.accountId=accountUniqueIdMap.get(caseUniqueIdMap.get(caseAccountPresent)).Id;
and in the System.debug, when you are trying to get the value from map, since SObject is changed, its not finding the value throwing NPE.
Hope this helps.
All Answers
Looks like you are using an SOBject as a key in your map. thats not really recommended. And your code is changing that SOBject in the line
caseAccountPresent.accountId=accountUniqueIdMap.get(caseUniqueIdMap.get(caseAccountPresent)).Id;
and in the System.debug, when you are trying to get the value from map, since SObject is changed, its not finding the value throwing NPE.
Hope this helps.
sorry stupid question come to think about it.
Thank you very much