in Education by
Is there any way to check if a list contains a certain element? I looked at the List functions and did not see any contain() function like Java or C# , so I was wondering how other people are handling this. I really need to use a List I cant use a Map like in this example here What I have now is really bad.. for (String s : allContacts) { for(String ic:insertedContacts) { if (s != ic ) { errorContacts.add(s); break; } break; } } Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
An apex list doesn’t support contains(). It is only available for Sets and Maps. But since you don’t want to use Maps, you can use Sets to solve this problem. For that, you can define a new set like: Set mySet = new Set(); Now you’ll need to use a method such as Set.addAll()to add all the elements of the lists to the set such as: mySet.addAll(myList);. You can now use the Set.contains() method to check the set for the element you’re looking for.

Related questions

0 votes
    I have recently discovered that salesforce.com is much more than an online CRM after coming across a Morrison's Case ... ' .Net route? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Is there a way to determine if a trigger is being executed by an API call or through the Salesforce Web Interface ... updating to 26.0) Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    How do I make a SOQL query like this? SELECT id FROM Account WHERE LastActivityDate = 30_DAYS_AGO This produces an ... = 30_DAYS_AGO ^ Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I would really appreciate if someone can guide me to check if a particular field is included in update call inside ... . Many thanks. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    Can someone tell me a easy method to check if a variable is a dictionary, list or anything else? I want to know ... is of which type. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Is there any reason for a class declaration to inherit from an object? I just found some code that does this ... class code follows... Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I have a web service class that will be in a managed package and distributed to multiple clients. The class ... accomplish this? Thanks Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Can someone tell me how can I Call a function in a string with function name in python program? E.x. Let's ... to perform this task. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Salesforce Einstein is considered to be the __________. A. Visualizer B. Personal Calculator C. Personal Data Scientist...
asked Nov 1, 2022 in Education by JackTerrance
0 votes
    We're currently looking at using the Force.com platform as our development platform and the sales guys and the ... such a platform. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I wanted to map custom fields of lead to map with custom field of contact' when converted using binding.convertLead ... should be made Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    The Salesforce.com API seems to assume that you will always use the app as an active user. Their ... require user interaction? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a page with a form that posts to salesforce.com's webto Lead service. I am trying to make an ... receiving website can see? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    The Salesforce.com API seems to assume that you will always use the app as an active user. Their ... require user interaction? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I have a page with a form that posts to salesforce.com's webto Lead service. I am trying to make an ... receiving website can see? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
...