• SFmaverick
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 53
    Replies

Summary: I've created a button that is displayed on a custom object. When clicked, I want this button to redirect the user to a Visualforce page with some parameters being passed from the current record. Here's the applicable section of code from the Button, VF Page, and Controller:

 

Button (This code is taking the value of the current records Week Start Date and Position and passing it into variables on the visualforce page):

 

 

/apex/scheduleview?BegDate={!Shift__c.Week_Start_Date__c}&Positions={!Shift__c.Position__c}

 

Visualforce Code:

Normally 'BegDate' and 'Positions' are generated from user input. BegDate is a text field (that receives dates: MM/DD/YYYY) and Positions is a drop down box that matches the position field on each Shift Object.

 

 

 

    <strong>Please enter the first day of the schedule you would like to see (mm/dd/yyyy):</strong> <apex:inputText value="{!BegDate}"/>
    <apex:selectList value="{!Positions}" Size="1">
        <apex:selectOptions value="{!items}"/>
        <apex:actionSupport event="onchange"></apex:actionSupport>
    </apex:selectList><p/>

 

 

Here is the controller code for handling this input:

 

 

    public String getPositions() {
        return Positions;
    }
    
    public void setPositions(String Positions) {
        this.Positions = Positions;
    }

    //Initializes and provides a get method for the user inputted date
    String BegDate;
    public String getBegDate (){
        return BegDate;
    }

     public void setBegDate (string BegDate) {
         this.BegDate = BegDate;
     }

 

 

Then of course these variables are used throughout the controller - but this is how they are brought in and initialized. What I'd like is for the current records values to be passed to the page when clicking the button - but I want the user to maintain the ability to also go to the visualforce page and enter their own input. This page is used to view and edit our schedule.

 

Any help would be greatly apprecaited - I read and attempted it quite a bit, but I've reset my code back to this default because it wasn't working.

 

 

 

 

 

 

 

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!

 

Background: I have a custom Object called Shift. It has lookup field to Contact. Each 'record' of the object Shift is just what you'd expect, it contains a Date and time that a Contact is scheduled to work.

 

Problem: I need to prevent users from scheduling the same contact for two shifts on the same date.

 

If there is a Shift where:  Contact = John Smith; Date = 9/15/2010, I don't want the user to be able to create another shift with those same values. I don't want to double book anybody.

 

I'm not sure of the simplest way to prevent this; or even a possible way. Thanks for any help / advice!

I'm generating a list of an SObject called Shift. The list is being pulled based on the date field. If I use the standard Today(), It correctly shows me the list of records for today.

 

My page takes user input as text and translates it to a Date called DayDate. I'd like to pull this list based on DayDate instead of Today().

 

Here's my Page code with the relevant parts highlighted:

 

<apex:page showHeader="false" standardStyleSheets="false" controller="ScheduleViewController">
<apex:form >
<apex:inputText value="{!BegDate}"/>
<!-- DayDate comes out correctly after inputting a date! -->
<apex:outputText value="{!DayDate}"/>
</apex:form>

<apex:outputPanel >
<apex:dataList value="{!TheList}" var="item"> <!-- Gets the list of shifts -->
<table border="0" bordcolor="00000" cellspacing="0" width="80%" bgcolor ="#000000"> <!-- Table that contains 7 day of weektables -->
<tr>
<td>
<table border="1" bordercolor="00000" width="100%" bgcolor="00000">
<tr>
<td bgcolor="#30C452">{!item.Shift_Summary__c}
<br></br>{!item.Shift_Summary_2__c}
<br></br>{!item.Shift_Summary_3__c}</td>
</tr>
</table>
</td>

<td>
<table border="1" bordercolor="00000" width="100%" bgcolor="00000">
<tr>
<td bgcolor="#30C452">{!item.Shift_Summary__c}
<br></br>{!item.Shift_Summary_2__c}
<br></br>{!item.Shift_Summary_3__c}</td>
</tr>
</table>
</td>

<td>
<table border="1" bordercolor="00000" width="100%" bgcolor="00000">
<tr>
<td bgcolor="#30C452">{!item.Shift_Summary__c}
<br></br>{!item.Shift_Summary_2__c}
<br></br>{!item.Shift_Summary_3__c}</td>
</tr>
</table>
</td>

<td>
<table border="1" bordercolor="00000" width="100%" bgcolor="00000">
<tr>
<td bgcolor="#30C452">{!item.Shift_Summary__c}
<br></br>{!item.Shift_Summary_2__c}
<br></br>{!item.Shift_Summary_3__c}</td>
</tr>
</table>
</td>

<td>
<table border="1" bordercolor="00000" width="100%" bgcolor="00000">
<tr>
<td bgcolor="#30C452">{!item.Shift_Summary__c}
<br></br>{!item.Shift_Summary_2__c}
<br></br>{!item.Shift_Summary_3__c}</td>
</tr>
</table>
</td>

<td>
<table border="1" bordercolor="00000" width="100%" bgcolor="00000">
<tr>
<td bgcolor="#30C452">{!item.Shift_Summary__c}
<br></br>{!item.Shift_Summary_2__c}
<br></br>{!item.Shift_Summary_3__c}</td>
</tr>
</table>
</td>

<td>
<table border="1" bordercolor="00000" width="100%" bgcolor="00000">
<tr>
<td bgcolor="#30C452">{!item.Shift_Summary__c}
<br></br>{!item.Shift_Summary_2__c}
<br></br>{!item.Shift_Summary_3__c}</td>
</tr>
</table>
</td>
</tr>
</table>
</apex:dataList>
</apex:outputPanel>
</apex:page>

 

 

 

 My Controller Code:

 

 

public class ScheduleViewController {
//Initializes and provides a get method for the user inputted date
public String BegDate { get; set; }

public Date DayDate;
// Turns the User's string input into a date
public Date getDayDate(){
if (BegDate==null) {
return null;
} else {
return stringToDate(BegDate);
}
}

//Gets TheList - an array of records from Shift__c where the Date equals DayDate (it works if I use Today(),
//but not DayDate, even when I verify that DayDate has the same value as Today()!

public List<Shift__c> getTheList() {
List<Shift__c> TheList = [SELECT Shift_Summary__c, Shift_Summary_2__c, Shift_Summary_3__c, Day_of_week__c, Date__c FROM Shift__c WHERE Date__c = :DayDate];
System.Debug('MY LIST:' + TheList);
return TheList;
}
//Converts a string from mm/dd/yy to a date
public Date stringToDate(String s){
//Input Date String is in the format mm/dd/yyyy
if(s.length()== 0)
{
return NULL;
}
else{
String[] stringDate = s.split('/');
Integer m = Integer.valueOf(stringDate[0]);
Integer d = Integer.valueOf(stringDate[1]);
Integer y = Integer.valueOf(stringDate[2]);
return date.newInstance(y,m,d);
}
}
}

 

 

 

 

Basically throughout my visualforce page, I'd like to take a variable that's been set, and I'd like to increment it by 1 several different times. I'm sure there's an easy way to make a call like this that I'm just not considering. Here's the current code:

 

Page Code - It's simply taking in a text value called BegDate and outputting a Date value called DayDate

 

 

<apex:page showHeader="false" standardStyleSheets="false" controller="TestViewController">
  <apex:form >
    <apex:inputText value="{!BegDate}"/>
    
    <apex:outputText value="{!DayDate}"/>
    
    <!-- This is where I'd like to output DayDate a second time, but incremented by 1>
    <apex:outputText value="{!DayDate}"/>
  </apex:form>
</apex:page>

 

Controller Code: It's taking the user input and converting it from text to a date format. I'd like to somehow make call to the controller from the visualforce page to increment DayDate by 1.

 

 

public class TestViewController {

    public String BegDate { get; set; }

    // Turns the User's string input into a date
    public Date getDayDate(){
        if (BegDate==null) {
            return null;
        } else {
            return stringToDate(BegDate);
        }
    }
    
    //Converts a string from mm/dd/yyyy to a date
    public Date stringToDate(String s){
      //Input Date String is in the format mm/dd/yyyy
      if(s.length()== 0)
      {
      return NULL;
      }
      else{
      String[] stringDate = s.split('/');
      Integer m =  Integer.valueOf(stringDate[0]);
      Integer d = Integer.valueOf(stringDate[1]);
      Integer y = Integer.valueOf(stringDate[2]);
      return date.newInstance(y,m,d);
      }
    }
}

 

 

 

Hi all,

 

I am trying to move a Trigger into Production but I am getting a 0% coverage when I validate it through Eclipse/Force.com.  I have 100% coverage when I run all tests in the sandbox.

 

The trigger will move the owner of an event to match the new lead owner once the lead is moved from a lead queue owner.

 

Here is the trigger and class.  I already received help from the discussion board on the trigger, thanks again in advance.

 

Any suggestions?

 

 

**** Trigger ****

trigger ownerupdate on Lead (after Update) {

List<Event> aplist = new List<Event>();

for(Lead t : Trigger.new){

IF(
(t.LeadSource == 'Telemarketing'
    && t.OwnerId != '00G30000001iNeKEAU' 
     && t.OwnerId != '00G30000001iNtxEAE'
      && t.OwnerId != '00G30000001uiO5'
       && t.OwnerId != '00G30000001iCwM'
        && t.OwnerId != '00G30000001uh70'
         && t.OwnerId != '00G30000001iNt5EAE'
          && t.OwnerId != '00G30000001ui8wEAA'
           && t.OwnerId != '00G30000001iNuC'
            && t.OwnerId != '00G30000001iNsL'
             && t.OwnerId != '00G30000001iNvZ'
              && t.OwnerId != '00G30000001jtEi'
               && t.OwnerId != '00G30000001tiXR'
                && t.OwnerId != '00G30000001ui8w'
                 && t.OwnerId != '00G30000001iNt5'
))

{List<Event> aps = [Select WhoId, Whatid, OwnerId from Event where WhoId = :t.Id];
   for (Event ap : aps)
   {       
      ap.OwnerId = t.OwnerId;

      aplist.add( ap );
   }

}}
update aplist;
}
trigger ownerupdate on Lead (after Update) {
    && t.OwnerId != '00G30000001iNeKEAU' 
**** Class Test Method **** public class ownerupdate { static testMethod void T1() { Id lId; Id eId; //CREATE 1 LEAD Lead l = new Lead(); l.LeadSource = 'Telemarketing'; l.lastname = 'Doe'; l.company = 'Test Company'; l.ownerId = '00530000003IFwV'; l.status = 'Open'; l.market__c = 'Atlanta'; Database.insert(l); lId = l.Id; //CREATE 2 Event Event e = New Event (); e.DurationInMinutes = 60; e.ActivityDateTime = date.today(); e.ownerId = l.ownerId; e.WhoId = l.Id; Database.SaveResult result = Database.insert(e); eId = e.Id; update e; {List<Lead> aps = [Select Leadsource, owner_convert_queue__c, id, OwnerId from Lead where id = :e.whoId]; system.debug('@@@apo=' + aps); } }}

 

Alex