You need to sign in to do that
Don't have an account?
pavan kumar 1864
null pointer exception on class
public class triggerclassss {
public set<id> aa= new set<id>();
public void accountss(list<contact>aaas){
system.debug('contacts----'+aaas);
for(contact c : aaas)
{
aa.add(c.accountid);
system.debug('account ids----'+ c);
}
map<id,account> hg = new map<id,account>([select id,name,phone from account where id in : aa]);
system.debug('account with id and records'+hg);
for(contact c : aaas)
{
if(c.accountid == hg.get(c.accountid).id)
{
system.debug('matching id with accuont and contact'+hg);
c.phone = hg.get(c.accountid).phone;
}
system.debug('assigning contact phone'+c.phone);
}
}
}
can anyone please tell me why null pointer exception displaying at line 23
public set<id> aa= new set<id>();
public void accountss(list<contact>aaas){
system.debug('contacts----'+aaas);
for(contact c : aaas)
{
aa.add(c.accountid);
system.debug('account ids----'+ c);
}
map<id,account> hg = new map<id,account>([select id,name,phone from account where id in : aa]);
system.debug('account with id and records'+hg);
for(contact c : aaas)
{
if(c.accountid == hg.get(c.accountid).id)
{
system.debug('matching id with accuont and contact'+hg);
c.phone = hg.get(c.accountid).phone;
}
system.debug('assigning contact phone'+c.phone);
}
}
}
can anyone please tell me why null pointer exception displaying at line 23
Please use belwo code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
Please use belwo code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Please use the contains key check:
Thanks,
Maharajan.C
Greetings!
In Map hg, When accountId is not found in the Map, then it will return NULL and you are trying to access the Id field from NULL.
So the error occurs, please check your accountId is present on the map.
Use this code to check it exists. If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
How can I connect with you?
if I got stuck at any point in the future.
you can drop email on :- mkrgupta1982@gmail.com