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

Yessss 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 set it will return true if list contains 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 element and if 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 🙂

 

Reference: Apex: New and Changed Classes

0 Comments

Leave a Reply

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?