Activity Forums Salesforce® Discussions How do I convert a list to a map in Salesforce?

  • Kirandeep

    Member
    September 7, 2020 at 1:41 pm

    Hi Marziya,
    You can convert like this :-
    List<Account> AccList = new List<Account>();
    Map<Id,Account> AccMap = new Map<Id,Account>();
    for(Account acc :AccList)
    {
    AccMap.put(acc.id,acc);
    }

  • Anuj

    Member
    September 7, 2020 at 1:54 pm

    Converting List to Map:

    1. //Converting list to map.
    2. Map<Id, Lead> mapFromList = new Map<Id, Lead>(leadList);

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos