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

Problem with Map's
Hi All,
Im trying to get the account name from a map in the example below, but get a null pointer excpetion, any idea why?
public class MainClass {
map<id, account> amap = new map<id, account>([select id, name, createdbyid from account]);
map<id,user> umap = new map<id, user>([select id, name from user]);
public void met1(){
map<id, opportunity> omap = new map<id, opportunity>([select id, name, createdbyid, accountid from opportunity]);
for(opportunity o : omap.values()){
system.debug(omap.get(o.id).name); //This works find and give me the opp name
system.debug(amap.get(o.accountid).name); // this one dosent ??
}
}
}
Im trying to get the account name from a map in the example below, but get a null pointer excpetion, any idea why?
public class MainClass {
map<id, account> amap = new map<id, account>([select id, name, createdbyid from account]);
map<id,user> umap = new map<id, user>([select id, name from user]);
public void met1(){
map<id, opportunity> omap = new map<id, opportunity>([select id, name, createdbyid, accountid from opportunity]);
for(opportunity o : omap.values()){
system.debug(omap.get(o.id).name); //This works find and give me the opp name
system.debug(amap.get(o.accountid).name); // this one dosent ??
}
}
}
Plesae Try this piece of code . Hope it's help you.
Regard Suraj