• JIM L
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
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 ??
            
         }   
    }   
}
  • December 02, 2017
  • Like
  • 0