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
KbhaskarKbhaskar 

global class er

hi,
 can you correct this 
Public static set<Id>getUniqueIds(list<SObject>sobs)
{
set<Id>Ids=new set<Id>();
for(SObject sob : sobs)
{
Ids.add(sob.Id);
}
return Ids;
}
Error: Compile Error: unexpected token: 'set' at line 1 column 14

 
Best Answer chosen by Kbhaskar
AmrenderAmrender

Hi,

Are you directly putting this code in your apex class? If yes, you forgot to mention the class name. Use below code

public class ClassName{
Public static set<Id>getUniqueIds(list<SObject>sobs)
{
set<Id>Ids=new set<Id>();
for(SObject sob : sobs)
{
Ids.add(sob.Id);
}
return Ids;
}
}

Regards
Amrender Ghangas

All Answers

ManojjenaManojjena
Hi ,
You have some error in your method signature .

Try like below .
 
Public static set<Id>  getUniqueIds(list<SObject>sobs){

Only problem is there is no space between method name and return type .

Let me know if it helps .
 
AmrenderAmrender

Hi,

Are you directly putting this code in your apex class? If yes, you forgot to mention the class name. Use below code

public class ClassName{
Public static set<Id>getUniqueIds(list<SObject>sobs)
{
set<Id>Ids=new set<Id>();
for(SObject sob : sobs)
{
Ids.add(sob.Id);
}
return Ids;
}
}

Regards
Amrender Ghangas
This was selected as the best answer
KbhaskarKbhaskar

Oops you are correct. Sorry not enough coffee this morning.