function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShadowlessKickShadowlessKick 

Capture SObject Set <String> Element

Am getting this error:
Initial term of field expression must be a concrete SObject: SET<String>

Any ideas? 

global Set<String> TheCoorNames = new Set<String>();
TheCoorNames.add("James Jones");
TheCoorNames.add("Sue Smith");

for (Integer TheIndex = 0; TheIndex < TheCoorNames.size(); TheIndex++){
String TheName;
TheName =  TheCoorNames.get[TheIndex].tostring;
}
Best Answer chosen by ShadowlessKick
ShadowlessKickShadowlessKick
Ramu_SFDC....Thank you for responding.

Raveen Murugesan...noted there is not a get method in the Set<String> class.

The reason that a Set<String> was being utilized was that a Set<String> only allows unique values.  Since that is what the process required, it seemed like the most logical path to take.  Unfortunatly, it appears that there is no way to retrieve element values from a Set<String>. 

Based on the suggestion from Raveen Murugesan the following was done. The unique values needed were collected in a Set<String>.  (This guaranteed uniqueness.)  The Set<String> was then loaded into a List<String>.  The List<String> does provide a get method but does not guarantee uniqueness.  Hokey, but I is what it is.

This is an example of what the code looked like:
//Put values in Set to ensure uniqueness.
Set<String> TheCoorNamesSet = new Set<String>();
TheCoorNamesSet.add('James Jones');
TheCoorNamesSet.add('Sue Smith');
TheCoorNamesSet.add('James Jones');
TheCoorNamesSet.add('Tim Adams');

//Put values from the Set into a List so the Lists class get value can be used. 
List<String> TheCoorNamesList = new List<String>( TheCoorNamesSet);

String TheName;
//Loop through the List and retrieve required values
for (Integer TheIndex = 0; TheIndex < TheCoorNamesList.size(); TheIndex++){
	TheName =  String.valueOf(TheCoorNamesList.get(TheIndex)); 
	System.debug('TheName: ' +  String.valueOf(TheCoorNamesList.get(TheIndex)) );
}

All Answers

Ramu_SFDCRamu_SFDC
Can you try this and let me know if it is working

TheName =  string.valueof(TheCoorNames.get[TheIndex]);
praveen murugesanpraveen murugesan
Hi,

You need to change the code like this,

1. TheName =  TheCoorNames.get[TheIndex].tostring;  // bracket is wrong 
 it should be TheCoorNames.get(TheIndex)

2. Already the value is string no need to covert that again to string. Anyway to covert to string you should use like this

TheName =  string.valueof(TheCoorNames.get(TheIndex));

3. There is no get method in set pls refer the following link you should you use list.

http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_set.htm

So your code should be like this

public list<String> TheCoorNames = new list<String>();
TheCoorNames.add('James Jones');
TheCoorNames.add('Sue Smith');

String TheName;
for (Integer TheIndex = 0; TheIndex < TheCoorNames.size(); TheIndex++){

TheName =  String.valueOf(TheCoorNames.get(TheIndex));
}

system.debug('~~~~~~~~'+TheName);

Mark this as solution if you got an answer.

Thanks,

Praveen Murugesan.

ShadowlessKickShadowlessKick
Ramu_SFDC....Thank you for responding.

Raveen Murugesan...noted there is not a get method in the Set<String> class.

The reason that a Set<String> was being utilized was that a Set<String> only allows unique values.  Since that is what the process required, it seemed like the most logical path to take.  Unfortunatly, it appears that there is no way to retrieve element values from a Set<String>. 

Based on the suggestion from Raveen Murugesan the following was done. The unique values needed were collected in a Set<String>.  (This guaranteed uniqueness.)  The Set<String> was then loaded into a List<String>.  The List<String> does provide a get method but does not guarantee uniqueness.  Hokey, but I is what it is.

This is an example of what the code looked like:
//Put values in Set to ensure uniqueness.
Set<String> TheCoorNamesSet = new Set<String>();
TheCoorNamesSet.add('James Jones');
TheCoorNamesSet.add('Sue Smith');
TheCoorNamesSet.add('James Jones');
TheCoorNamesSet.add('Tim Adams');

//Put values from the Set into a List so the Lists class get value can be used. 
List<String> TheCoorNamesList = new List<String>( TheCoorNamesSet);

String TheName;
//Loop through the List and retrieve required values
for (Integer TheIndex = 0; TheIndex < TheCoorNamesList.size(); TheIndex++){
	TheName =  String.valueOf(TheCoorNamesList.get(TheIndex)); 
	System.debug('TheName: ' +  String.valueOf(TheCoorNamesList.get(TheIndex)) );
}

This was selected as the best answer