You need to sign in to do that
Don't have an account?
m@x~W0W~
Error : Illegal assignment from LIST<Student__c> to SET<Student__c>
public class AsgClass2
{
List<Class__c> clid = [Select id from Class__c];
map<id,Set<Student__c>> newMap = new map<id,Set<Student__c>>();
public map<id, Set<Student__c>> trdata()
{
for(class__c cl:clid)
{
Set<Student__c> stset = [Select id from Student__c where Class__c = :cl.id];
newMap.put(cl.id,stset);
}
return newMap;
}
}
Instead of
Set<Student__c> stset = [Select id from Student__c where Class__c = :cl.id];
Use below
List<Student__c> stset = [Select id from Student__c where Class__c = :cl.id];
Do it like this
public class AsgClass2
{
List<Class__c> clid = [Select id from Class__c];
map<id,Set<Student__c>> newMap = new map<id,Set<Student__c>>();
public map<id, Set<Student__c>> trdata()
{
for(class__c cl:clid)
{
Set<Student__c> stSet = new Set<Student__c>();
List<Student__c> stLst= new List<Student__c>();
stLst = [Select id from Student__c where Class__c = :cl.id];
stSet.addAll(stLst);
newMap.put(cl.id,stset);
}
return newMap;
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Yes sure it will remove duplicates because the list is ultimately added to set and there it will remove duplicates.