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, 2022 in SalesForce by surbhi
• 3,810 points
197 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.

Hope this helps!

Check out Salesforce Certification here.

Thanks!

answered Mar 17, 2022 by CoolCoder
• 4,400 points

edited Jun 27, 2023 by Khan Sarfaraz

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, 2022 in SalesForce by surbhi
• 3,810 points
3,262 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, 2022 in SalesForce by CoolCoder
• 4,400 points
2,042 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, 2022 in SalesForce by CoolCoder
• 4,400 points
2,884 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, 2022 in SalesForce by CoolCoder
• 4,400 points

edited Jun 19, 2023 by Khan Sarfaraz 15,297 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
2,730 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,030 points
728 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,030 points
476 views
0 votes
2 answers

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 535 views
0 votes
1 answer

Sets in Salesforce

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

answered Mar 15, 2022 in SalesForce by CoolCoder
• 4,400 points
465 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, 2022 in SalesForce by CoolCoder
• 4,400 points
1,388 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP