+ Start a Discussion
prasanth puvvada 4prasanth puvvada 4 

please explaint map with integer, account

i am not able to understand        Map<Integer, List<Account>>  

If this is >>>>>>>>  Map<Integer, Account>   the map.put(1,name='prasanth');      map.put(2,name='kiran');    is this line is correct? 

please explaing example for Map<Integer, List<Account>>   .  Thanks in advance.

I understoond map<id, account>    and please tell  map<id,list<account>>    thanks in advance.  
Shrikant BagalShrikant Bagal
In your scenarion w you are creating Map with integer and List of Account Records so the correct line is as follow:

 Map<Integer, Account> mapAccount = new  Map<Integer, Account>();

mapAccount.put(1, new List<Account>() { new Account(Name="TestAccount") });

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
 
Jigar.LakhaniJigar.Lakhani

Hello,

Map<Integer,List<Account> is the combination of key and value pair. Where key is the integer means any index number as well value is the list of account records. So below is the example to prepare map of index number(Integer) and accounts.
Suppose you have list of account and from that list you need to prepare map.
Assume that in your account list you have AcountNumber field which have number values like 0,1,2,3...
 

Map<Integer,List<Account> mapAccounts = new Map<Integer,List<Account>();
for (Account objAccount:listAccounts) {
	if (mapAccounts.ContainsKey(objAccount.AccountNumber) == false) {
		List<Account> listAccount = new List<Account>();
		listAccount.Add(objAccount);
	} else {
		mapAccounts.Get(objAccount.AccountNumber).Add(objAccount);
	}
}

System.Debug('####  '+mapAccounts);

And about you line
If this is >>>>>>>>  Map<Integer, Account>   the map.put(1,name='prasanth');      map.put(2,name='kiran');    is this line is correct?
- It is not correct, you need to have correct format as Shrikant suggested.

About map<id,list<account>>
- You can understand that map based on above example.

Thanks & Cheers,
Jigar (pateljb90@gmail.com)

Amit Chaudhary 8Amit Chaudhary 8
Hi 

In below code you are storing Account Detail base on number.
Map<Integer, Account> map = new Map<Integer, Account>();
map.put(1,new Account(name='prasanth'));      
map.put(2,new Accoont(name='kiran'));
Please read below post that will help you.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm

If you want to use below line meanse you want to store list of account base on number.

Map<Integer, List<Account>> map = new Map<Integer, List<Account>>();

Both are valid code.
Please let us know if this will help you.
Amit Chaudhary 8Amit Chaudhary 8
Please let us know if above solution helps u. 
Amit Chaudhary 8Amit Chaudhary 8
Please let us know if above solution helps u.