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
SFmaverickSFmaverick 

Advice for Schedule Project

Background - I have an Object in Salesforce called Shifts, where the user will enter a shift, they are required to enter:


Date

Start Time

End Time

Department

 

The Employee isn't always entered yet, because somebody has to be assigned, but a lot of times it's there. The reports from Salesforce are limited in how you can display them, it's a lot harder to see where the open shifts are and when people are free if you view these shifts in a list view. Prior to Salesforce, we used Excel and we had something like this (this is just a snippet, It's MUCH larger with many more departments and employees)

 

Schedule Snippet

 

I have all the things you see in this view available in Salesforce. I have a formula field that generages everything in the little boxes. I need some advice / help on how I can write in visualforce, to put the Shift summary formula field under a column based on that shift's Date value. Basically, from left to right I'd like them organized by date, with one day per column. From top to bottom I'd like them organized alphabetically.

 

Any ideas / suggestions?

 

Thanks!

dsh210@lehigh.edudsh210@lehigh.edu

Assuming you are only displaying one week at a time, it seems to me like you could make each column a pageblock table by querying for the date you want (day of the week, etc.). If you then do an ORDER BY <Department Object>, when it makes the rows it will place the rows in that order. However, I am not sure what the gaps in your schedule indicate, since this solution would not place any gaps. Using CSS on the pageblock tables you could get them to look virtually however you want. It would be possible to do this displaying every date (and adding new ones) if you use an apex repeat to make the tables (make a new table for each date).

 

This solution requires the use of Visualforce with an APEX controller on the back end, so it may seem somewhat daunting if you have not used APEX, but the help is very good.

 

Hope that helps a bit,

DH

SFmaverickSFmaverick

The empty spots weren't really programmed in, we just tried to limit the length of the schedule to a single page for ease of printing, and then when possible we put shifts in the same department on the same line; However there will be too many departments to give a unique line for each, and some departments will require two lines, so there's no reasonable way to program it.

 

I have some Apex code experience (I've put a few triggers into production), I don't really have visual force experience (although I'm somewhat familiar with HTML.

 

If it's not too much work, can you give me a snippet of code as an example of how declaring / inserting data for a single column table that Draws from the Shift__c object would look.

 

Ideally I'll be putting things in place to make it start from the last monday and going a week, but I can figure all that logic / code out after I get the base down for creating each column.

 

Thanks for the help so far.

dsh210@lehigh.edudsh210@lehigh.edu

First off, I cannot speak highly enough of how the component reference is set up. When you are editing a visualforce page, it can be opened via the button near the top (by save). It will give you a great description of how each visualforce component is used and what each parameter is for.

 

For your problem here you are going to want each column to be an <apex:pageblocktable>. What you do with these is supply a list, and it iterates over the list doing whatever you specify. This might look like the following:

 

 

//Visualforce code
<apex:pageBlockTable value="{!TheList}" var="item">
 <apex:outputText value="{!item.Some_Field__c}" />
</apex:pageBlockTable>

//Apex Code
public List<Some_Object__c> getTheList() {
 List<Some_Object__c> theList = [SELECT Some_Field__c FROM Some_Object__c ORDER BY Department_Field__c]; //this will select all, use a WHERE clause to limit based on a field (like a date).
 return theList;
}

 

 

The pageblocktable will then take each element of TheList that was returned, and print out that item.Some_Field__c in a new row. You can print out as many things as you want in that row, it will only make a new one when it it moves onto the next iteration of items.

 

That current setup will print every item in one column, but you can see how it would be easy to make 5 columns with 5 get methods (like getMondayList()) and such. You would just need to have a WHERE clause on your query to filter your data.

 

Hope this helps,

DH

SFmaverickSFmaverick

Am I going to be restricted to 4 columns if I'm using the Apex PageBlock? I'd like to have 7 columns so I can display an entire week side by side.

dsh210@lehigh.edudsh210@lehigh.edu

No, if you make each column its own table (of 1 column) you can have as many as you want. You are only restricted by the APEX governor limits (which should not be an issue for something small like this). After you have your 7 tables, just apply some styles to them to position them like your screenshot above.

bmabma

if you are planning to do your own styling for the table, can you use <apex:dataTable> instead of <apex:pageBlockTable>?

 

Include SF styles / javascript&colon; <apex:pageBlockTable>

Does not include SF styles / javascript&colon; <apex:dataTable>

 

In this case, you can style the page anyway you wanted without much limitation.

SFmaverickSFmaverick

Ok, I've made my attempt, but I'm not able to save the Visualforce page for some reason. Here's my code for both.

 

Visual Force Page

 

<apex:page controller="ScheduleViewController">
<apex:pageBlock >
List<Shift__c> TheList = New List<Shift__c>();
TheList.getTheList(TheList);
    <apex:pageBlockTable value="{!TheList}" var="item">
        <apex:outputText value="{!item.Shift_Summary__c}" />
    </apex:pageBlockTable>
</apex:pageBlock>

</apex:page>

 When I try to save the Visual Force Page, I get the error "Error: The element type "Shift__c" must be terminated by the matching end-tag "</Shift__c>". at line 9"

 

 

Class (Apex) Code

 

public class ScheduleViewController {
    public List<Shift__c> getTheList() {
        List<Shift__c> TheList = [SELECT Shift_Summary__c FROM Shift__c WHERE Date__c = TODAY ORDER BY Shift_Summary__c];
        return TheList;
    }
}
dsh210@lehigh.edudsh210@lehigh.edu

It looks like you are mixing some Apex in on the Visualforce page. Take out the 

List<Shift__c> TheList = New List<Shift__c>();
TheList.getTheList(TheList);

 

It is reading your <Shift__c> as a Visualforce tag, so it is expecting a terminating tag, despite the fact that it is not a tag at all. You cannot put pure Apex code in a visualforce page.

SFmaverickSFmaverick

I had previously saved it and tried it without that there before, but then when I viewed the page, it wasn't showing anything and it was my thought that it was because there was no call to the getTheList function inside of the ScheduleViewController Class.

 

Without something like what I put in there, how does !TheList, ever get populated?

dsh210@lehigh.edudsh210@lehigh.edu

This is something weird that Force.com does. When you say {!TheList}, what actually happens is it goes first to the standard controller and asks, is there a method called getTheList()? If the answer is no (which it is), it will look to any controller you have specified and ask the question again, is there any method called getTheList()? If there is not, it will throw an error and not let you save your page. However, you have the method, so it is returning the list fine. The issue must be that your SELECT statement is returning an empty list.

 

If you are not familiar with debugging, I would look on these forums and get the gist of it, it is a lifesaver.

 

In short, put a statement like System.Debug('MY LIST: ' + TheList); inside your getTheList() method (after your select, but before your return). Inside your setup area (where you have links on the left for pages and apex classes, etc, there is an item at the bottom called monitoring. Inside that is a link to the debug logs. Create a new request (I always use the Admin User). Now, when you load your page, it will output a debug log explaining exactly what happened. It looks very daunting when you first look at it, but that is where your System.Debug() comes in handy. Search (case sensitive) for MY LIST. That will be your debug message, which will output what the selected list was.

 

Using that debug method you will have a much easier time troubleshooting your pages.

 

Hope that helps,

DH

SFmaverickSFmaverick

Alright, well the results of the debugging tell me that it is puling the lists. I can see all the values it's pulling in my debug log, it's accurately pullling the shift_summary__c field from all of the records that are intended.

 

So I guess that means I'm doing something wrong when i'm displaying it?

SFmaverickSFmaverick

There's definitely an issue with how it's being displayed, but I can't seem to figure out what.

 

I kept the controller unchanged and I changed the Page code to look like this:

 

 

<apex:page controller="ScheduleViewController">
<apex:dataList value="{!TheList}" var="item">
    <apex:repeat value="{!item}" var="items">
       <apex:outputText value="{!items.Shift_Summary__c}" />
    </apex:repeat>
</apex:dataList>

</apex:page>

 

 

This gives me (although it's unformatted), a list with the values of Shift_Summary__c. Now if there's a way to format this output to look like the screen shot I posted, I'd be more than happy to work with it, but I'm not sure how I'd do that.

 

Also, the field I'm outputting is a formula field with hard coded line breaks in it, is it possible to get those linebreaks coded in to be effective with the display? I'm not sure how i'd accomplish this since the line breaks are are within a single field. Maybe it would be possible for me to break the three lines from the summary field up into seperate fields and then concatenate them together coding the line breaks in between?