You need to sign in to do that
Don't have an account?
SOQL Queries
Currently I have a visualforce page that takes a Date as user input and returns a table of records. Each column of the table represents a list of Shifts, the first list being the list of shifts that occurs on the date the user input - and then each column after incrementing that date by one.
Here's a quick visual of what I described without the actual records showing (confidential information):
Below each day, the records are output in an HTML Table. Each day is currently a seperate query that looks like this:
public List<Shift__c> getTheList2() { Date NewDate = IncrementDayDate(1); If (Positions == 'Tech'){ List<Shift__c> TheList2 = [SELECT Shift_Cancelled__c, Notes__c, ID, BGCOLOR__c, Shift_Summary__c, Shift_Summary_2__c, Shift_Summary_3__c, Day_of_week__c, Date__c FROM Shift__c WHERE Date__c = :NewDate AND (Position__C = 'Tech' OR Position__C = 'Pharmacy Support' OR Position__C = 'Material Handler') ORDER BY Shift_Summary__c, Shift_Summary_2__c]; return TheList2; } else { List<Shift__c> TheList2 = [SELECT Shift_Cancelled__c, Notes__c, ID, BGCOLOR__c, Shift_Summary__c, Shift_Summary_2__c, Shift_Summary_3__c, Day_of_week__c, Date__c FROM Shift__c WHERE Date__c = :NewDate AND Position__C = 'RPh' ORDER BY Shift_Summary__c, Shift_Summary_2__c]; return TheList2; } }
This ends up meaning 7 queries to the server for the lists, although the only difference in the filter is the Date. Ideally I'd only pull this list once and then seperate out each of the 7 days. Any ideas on how to do this?
Can you build a list, from a list? If Master_List exists as a List of all of the records for each day, could I pull each individual list from it like this? I want to avoid making 7 calls to the server to improve performance and code efficiency.
List<Shift__c> TheList2 = [SELECT Shift_Cancelled__c, Notes__c, ID, BGCOLOR__c, Shift_Summary__c, Shift_Summary_2__c, Shift_Summary_3__c, Day_of_week__c, Date__c FROM :Master_List WHERE Date__c = :NewDate AND Position__C = 'RPh' ORDER BY Shift_Summary__c, Shift_Summary_2__c];
return TheList2;
}
}
It would be even better if I could pull the Master List, and use something in my Visualforce code to spit out each day. The shorter my Apex code becomes - the easier future modification comes. I'm getting close to reaching governor limits on this page due to other queries, so I wanted to find room to improve the code.
Thanks for your help!
This will return your list with every days of the week at once, with it sorted by the day initially.
Actually this is slightly better...
The problem is that still makes 7 individual calls to the server - it might actually be even slower because I'd have to do 'refreshes' of each section where this function was called in order to generate and display the next day.
Ideally my new server call would echo something like this and would pull all 7 days in one request from the server:
What I'm trying to figure out is how I can logically seperate each day out of this list to iterate over it on my visualforce page so it can be output into the HTML Table. Can you build a list from a list?
Well, I built a list from a list in what I gave you before. If it is taking you 7 queries still then its because you did not adjust your current code to fit what I gave you.
The code I gave you puts the next 7 days of a week into a list, and then returns everything for the next 7 days. It does pretty much what you are asking, except that other code needs adjusted to accomadate for it.
and yes, the code I gave you does this.
I'm sorry maybe you can make me understand then - how this will output correctly without reconstructing that list 7 times, which would require seven seperate pings to the server. Here is how I'm calling the lists I currently have from my visualforce page - Each one iterates through the list providing one column in the table - each column represents one day (one date). If I make this same call 7 times, am I going to get one day at a time from your code?
I think I understand your meaning a little bit better. I have not tested this, but with all syntax correct it should either give you what you want or enough for you to slightly modify to give what you want.
Nested repeats to bring out the different days.
Site URL : https://techinstructs.com/