Posts

Showing posts from November, 2020

Efficient way to write apex code

Image
Set.contains(element) Vs List.contains(element)  Guess What if I tell small things Matter!!!                     If you’re having a cup of tea, pause for a moment because next two minutes will reveal something simple yet less known it the world of Salesforce                     Set && List your favorite go to during the typical development cycle. But going forward you will definitely double check before using them. For Instance, look at this example                     Take two set of collections (Set<Integer> and List<Integer>). Now the crux of the discussion which one will give better performance. Lets get technical Which will give better performance Set or List ?      a.     I f collection is List :  List < Integer > listInteger = new List < Integer > (); for (Integer i = 0; i < 100000; i++) { listInteger.add(i); } Long start = DateTime.now().getTime(); System.debug('get ' + listInteger.contains(100000)); Long finish = DateTime.now