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
DarrellDDarrellD 

Put SObject List field into a Set

Not sure what missing here, something obvious I think. Had below to iterate through List to add fields in list to 3 Sets. This seems redundant first off, second it's not working, 3rd there's a better way to do it.  Adding to set so I can remove the duplicate field values. Two example records and my goal are:.

 

Record 1: July, Monday;Wednesday;Saturday, 2013

Record 2: July, Wednesday;Friday, 2013

 

Trying to get to:

yearsSet (1 record) - 2013

monthSet(1 record) - July

daysSet(4 records) - Monday, Wednesday, Friday, Saturday

 

List<Schedule_Connection__c> schconnList = [select id, Address_Type__c, Address_Type__r.Provider__c, Address_Type__r.Address__c,Schedule_Development__r.Scheduled_Days__c, Schedule_Development__r.YearNumber__c, Schedule_Development__r.MonthNumber__c, Schedule_Development__r.Start_Time__c,
Schedule_Development__r.End_Time__c from Schedule_Connection__c where Id in:schconnections];

Set<Integer> yearsSet = new Set<Integer>(), monthsSet = new Set<Integer>();
Set<String> daysSet = new Set<String>();
For(Schedule_Connection__c record : schconnList) {
yearsSet.add((record.Schedule_Development__r.YearNumber__c).intvalue());
monthsSet.add((record.Schedule_Development__r.MonthNumber__c).intvalue());
daysSet.addall((record.Schedule_Development__r.Scheduled_Days__c.split(';')));

 

gedeefgedeef

what about removing this line ?

yearsSet.addl((schconnList.Schedule_Development__r.YearNumber__c).intvalue());

No idea why it's here...

What do you mean : not working ? doesn't execute (error message ?) or doesn't do what expected ?

DarrellDDarrellD

That was a copy and paste problem. That line was when I was trying an addAll. I just edited original post as that line wasn't really there.

 

I really shouldn't have said not working because I'm not sure. The code is inefficient and causing log files to fill up when it hits this section so I can't see what the output is. No way that logs should be filling up at this spot given what I'm trying to do so that's one large issue.

gedeefgedeef

I would 1st check that the query is ok and sends results, that should be at the begining of the log. [edit : of course no, you have much code before it :))]

then I would add a "limit 10" to the query to reduce the size log and try to see the error...