function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhishek_NewAbhishek_New 

Will a Map contain only id's of a record when populated through select statement..??

map<id,case> caseLst =new map<id,case>([select id,AccountId,status from case where Accountid=:mp.keyset()]);

here mp.keyset() contains several Accountids that the cases are related to.

 

now my question is will the above MAP's key always contain the ids of case ? Is there any way so that I can keep AccountId field of a case object as a key of the MAP when populated through SELECT statement ?

 

I tried to give--

map<String,case> caseLst =new map<String,case>([select AccountId,status from case where Accountid=:mp.keyset()]);

 

But then also caseLst.keyset() contains only ids of the case records not the AccountIds.

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu
Yeah, you are right.
But you can code by yourself, like

map<id, case> mycase = new map<id, case>();
for(case cs : [select id, AccountId, status from case limit 5]) {
mycase.put(cs.accountId, cs);
}

All Answers

Jia HuJia Hu
Yeah, you are right.
But you can code by yourself, like

map<id, case> mycase = new map<id, case>();
for(case cs : [select id, AccountId, status from case limit 5]) {
mycase.put(cs.accountId, cs);
}
This was selected as the best answer
Abhishek_NewAbhishek_New

Ys..Thats what I have done...Ok..Anyhow Thanks for confirmation.