Activity › Forums › Salesforce® Discussions › How to check if list contains the specified element in Salesforce ? Salesforce® Discussions How to check if list contains the specified element in Salesforce ? Posted by Kirandeep on October 27, 2020 at 3:22 PM How to check if list contains the specified element in Salesforce ? Anuj replied 5 years, 7 months ago 2 Members · 1 Reply 1 Reply Anuj Member October 27, 2020 at 3:28 PM Define a new Set. Set<String> mySet = new Set<String>(); Use the Set. addAll() method to add all of the List elements to the set. mySet. addAll(myList); . Use the Set. contains() method to check the Set for the element you’re looking for. Log In to reply. Public All Members My Connections Only Me PublicAll MembersMy ConnectionsOnly Me Public All Members My Connections Only Me