Tuesday 11 October 2016

How to convert List to Map in Salesforce

Here is the simple way to convert list of sobject records to map.

Assigning query result to List:

  1. //Assigning return query result to the list.
  2. List<Lead> leadList = [SELECT Id, Name FROM Lead];

Assigning query result to Map:

  1. //Directly assigning return query result to the map.
  2. Map<Id, Lead> leadMap = new Map<Id, Lead>([SELECT Id, Name FROM Lead]);

Converting List to Map:

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

4 comments:

  1. very informative blog and useful article thank you for sharing with us , keep posting learn more aboutsalesforce training,salesforce online training

    ReplyDelete
    Replies
    1. best training institute to not only get job but to survive in job & be stable:
      www.salesforcestart.com

      Delete
  2. I have been searching to find a comfort or effective procedure to complete this process and I think this is the most suitable way to do it effectively. Garmin Map Update Download

    ReplyDelete

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...