Sets in Salesforce

0 votes
If I have to access an element of a list , I can use the get() method . EX:- myList.get(1) would return the element at the 1st index.But the same seems invalid for sets. I am aware that set is an unordered collection. But does that mean that we cant access individual elements of a set?
Mar 10 in SalesForce by surbhi
• 3,810 points
13 views

1 answer to this question.

0 votes

LIST class provides you the get method, but there is no get method in SET. As SET is an unordered collection, it is not certain to get the correct element in correct index.

The solution to this problem is, Cast the SET to LIST.

SET<String> str = new Set<String>();
str.add('4');
str.add('1');
str.add('2');
str.add('3');


string f = (new list<string>(str) )[0];
string s = (new list<string>(str) )[1];

You can get the element by index by this way.

answered Mar 17 by CoolCoder
• 4,360 points

Related Questions In SalesForce

0 votes
1 answer

Json response to be deserialized in Apex salesforce lightning

Because some fields in Apex are reserved ...READ MORE

answered Mar 2 in SalesForce by surbhi
• 3,810 points
86 views
0 votes
1 answer

How can i use select * in SOQL query in Salesforce?

SOQL is not the same as SQL. ...READ MORE

answered Mar 3 in SalesForce by CoolCoder
• 4,360 points
81 views
0 votes
1 answer

How to Update RecordTypeId field in Lightning record form in salesforce?

A critical action that messes everything up ...READ MORE

answered Mar 3 in SalesForce by CoolCoder
• 4,360 points
170 views
0 votes
1 answer

Salesforce picklist values not showing up in picklist

For both standard and custom objects, go ...READ MORE

answered Mar 3 in SalesForce by CoolCoder
• 4,360 points
238 views
+2 votes
2 answers

Salesforce Interview questions

Here are some questions very important for ...READ MORE

answered Jan 11, 2019 in Career Counselling by Suresh
• 720 points
1,826 views
0 votes
1 answer

How to connect to salesforce from tableau?

Hi, follow these steps to connect to Salesforce: 1. ...READ MORE

answered Mar 25, 2019 in Tableau by Cherukuri
• 33,010 points
286 views
0 votes
1 answer

Power BI - Salesforce

Hi, Follow below steps: 1. Go to Data source. 2. ...READ MORE

answered Mar 25, 2019 in Power BI by Cherukuri
• 33,010 points
171 views
0 votes
1 answer

What is the best training for Salesforce ADM-201 Exam?

Hi @Vardhan, I took Edureka's Salesforce Training that covers all ...READ MORE

answered Jun 3, 2021 in Others by Jaya
• 140 points

edited Dec 22, 2021 by Soumya 201 views
0 votes
1 answer

Sets in Salesforce

LIST class provides you the get method, but there ...READ MORE

answered Mar 15 in SalesForce by CoolCoder
• 4,360 points
25 views
0 votes
1 answer

Check string value in salesforce test class

Because the field objCase.standard_or_nonstandard_c is set to ...READ MORE

answered Mar 3 in SalesForce by CoolCoder
• 4,360 points
28 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP