Skip to main content

Posts

Showing posts with the label Set

Apex programming Tricks

Convert List to Map  Lets assume we have list of accounts record and we need to create map of Id to Account record. Traditional  approach is using Iterating over list of Account records and storing in a Map. but the easiest approach is  List < Account > lstofAccount = [ Select  id,name  from   Account   limit   10 ]; system .debug( 'lstofAccount--' +lstofAccount); Map < Id , Account > map_account =  new   Map < Id , Account >(lstofAccount); system .debug( 'map_account--' +map_account); 11 : 00 : 02 : 011   USER_DEBUG  [ 4 ]| DEBUG | map_account--{ 00111000029360 TAAQ = Account :{ Id = 00111000029360 TAAQ ,  Name = Area   Agency   on   Aging   Region   9 ,  RecordTypeId = 012360000005 HcsAAE },  00111000029360 UAAQ = Account :{ Id = 00111000029360 UAAQ ,  Name = AULTMAN   HOSPITAL ,  RecordTypeId = 012360000005 HcsAAE }} Remove Dupl...