Oct 4, 2024
61 Views
Comments Off on The Most Awaited Feature “List Contains” is Now Available – Spring’18
0 0

The Most Awaited Feature “List Contains” is Now Available – Spring’18

Written by

Yes, you heard it right! Now no more replicating List to Set. You can directly use contains over List.

Salesforce Spring ’18 Release

contains(listElement):

Same as a set, it will return true if a list contains an element.

List<String> listStrings = new List<String>();
listStrings.add(“One”);
listStrings.add(“Two”);
listStrings.add(“Three”);
listStrings.add(“Four”);
System.debug('Check Contains Four-->'+ listStrings.contains('Four'));

Output:

Check Contains Four–>True

indexOf(listElement):

You can consider as an extra feature. It returns the position of the element and if the element is no there it returns -1.

List<String> listStrings = new List<String>();
listStrings.add(“One”);
listStrings.add(“Two”);
listStrings.add(“Three”);
listStrings.add(“Four”);
System.debug(‘Index of Ten–>’+ listStrings.indexOf(‘Ten’));

Output:

Index of Ten–>-1

Keep Smiling!!!!

Happy Coding 🙂

Article Categories:
Salesforce
https://thestarbiznews.com/

Expertise: Global Macroeconomics, Business Strategy, Emerging Markets Bio: Rajeev Sharma is a seasoned investment strategist with over two decades of experience navigating the ever-evolving global market landscape. A veteran of Wall Street and a sought-after advisor to Fortune 500 companies, Rajeev brings a wealth of knowledge and expertise to TheStarBizNews. His insightful analyses of global economic trends, coupled with his keen understanding of regional specificities, provide invaluable guidance for businesses and investors alike. Fluent in four languages and a frequent speaker at international conferences, Rajeev brings a cosmopolitan flair to his writing, drawing connections between seemingly disparate events to paint a clear picture of the interconnected world we live in.