+ Start a Discussion
Minky VaidMinky Vaid 

save, cancel and save and new not working

hi
save ,cancel and save and new buttons are not working on my visualforce page. Below is the code
And I want the assigned to defaults to the current user. Can anybody Help!!!

Controller//
public class LatestTask {public Task ta{get;set;}

    public LatestTask(ApexPages.StandardController controller) {

    }
  public Attachment file;
        public Attachment getfile(){
            file = new Attachment();
            return file;
        }
        public PageReference saveattachment(){
            string recordid = System.currentPageReference().getParameters().get('id');
            Attachment attach = new Attachment(
                parentid = recordid,
                name = file.name,
                body = file.body);
            insert attach;
            return null;
        }
   
    
 public void Cancel() 
  { 
  }    
  public void SaveNewEvent()
  {           
  } 
  public void SaveNewTask() 
  {            
  }    
  public ApexPages.PageReference save() 
{
  // I can do custom logic here before I save the record.
  
ApexPages.StandardController controller = new ApexPages.StandardController (ta);

  try {

    controller.save();
  
}
  catch(Exception e) 
{
    return null;

  }
  
return controller.view();

}
}
VF Page//
 
<apex:page tabStyle="Task" id="page1" standardController="task" extensions="LatestTask"  standardStylesheets="false">
<apex:form >
        <apex:pageBlock title="CSR Call" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="save" title="save"/>
<apex:commandButton action="{!SaveNewTask}" value="Save & New Task" title="Save & New Task"/>
<apex:commandButton action="{!SaveNewEvent}" value="Save & New Event" title="Save & New Event"/>
<apex:commandButton action="{!Cancel}" value="Cancel" title="Cancel"/>
</apex:pageBlockButtons>

<apex:pageBlockSection Title="Information" columns="2">
               <apex:inputField value="{!task.Subject}" id="subject" required="true"/>
               <apex:inputField value="{!ta.ownerid}" id="user"/>
               
               <apex:inputField value="{!task.ActivityDate}" onfocus="DatePicker.pickDate(false, 'DueDate', false);"/>
                <apex:inputField value="{!task.Status}"/>
                
                
                
                <apex:inputField value="{!task.Priority}" />
                <apex:inputField value="{!task.Disposition__c}" />
                <apex:inputField value="{!task.Description}  " />
                <apex:inputField value="{!task.Call_Type__c}   " />          
                
                

</apex:pageBlockSection>


<apex:pageblockSection Title="Related To" columns="2"  >


                               
               
                
 <apex:inputField value="{!ta.WhatId}"/>
 <apex:inputField value="{!ta.WhoId}"/>
</apex:pageblockSection>

<apex:pageBlockSection Title="Recurrence">
<apex:pageBlockSection id="pbs3" >
<apex:inputfield value="{!task.IsRecurrence}" onclick="CheckDiv()"/> 

</apex:pageBlockSection>
</apex:pageBlockSection>
 
  <div id="Recurrencediv"  style="display:none;">   
            <apex:pageBlockSection columns="1" id="pbs4" > 
                <apex:pageBlockSectionItem id="pbsi1" >
                    
                    <table border="0px">
                            <tr>
                                <td style="width:120px;">&nbsp;</td>
                                <td><b>Frequency</b></td>
                                <td style="width:80px;"></td> 
                                </tr>  
                                </table>                                                                                                     
                                <div>
                                        <input type="radio" id="Dailydiv" checked="true"  name="checkrctype" value="RecursEveryWeekday"/>Daily<br/>
                                        <input type="radio" name="checkrctype"  value="Weekly"/>Weekly<br/>
                                        <input type="radio" name="checkrctype"  value="RecursMonthly"/>Monthly<br/>
                                        <input type="radio" name="checkrctype"  value="RecursYearly"/>Yearly
                                    </div>
                               
                               <div name="Daily" id="Daily">
                                                                
                                            <input type="radio" id="RecursEveryWeekday"   name="recurrencetype" value="RecursEveryWeekday"/>Every weekday<br/>
                                            <input type="radio" id="RecursDaily"   name="recurrencetype" value="RecursDaily"/>Every
                               </div>
                                      
                                    </apex:pageBlockSectionItem>
                                       </apex:pageBlockSection> 
                                        </div> 
                
<apex:pageBlockSection >
<apex:inputField value="{!task.RecurrenceStartDateOnly}  " />
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputField value="{!task.RecurrenceEndDateOnly}  " />
</apex:pageBlockSection>
     
        <apex:pageBlockSection Title="New Attachment" >
        <apex:inputFile value="{!file.body}" fileName="{!file.name}"></apex:inputFile>
        <apex:commandButton value="save" action="{!saveattachment}"/>
</apex:pageBlockSection>
<apex:pageBlockSection Title="Reminder" Columns="2">
<apex:inputField value="{!task.IsReminderSet }"   />
<apex:inputField value="{!ta.Reminder__c}" onfocus="DatePicker.pickDate(false, 'DueDate', false);" />

<div class="datePicker" id="datePicker">
<div class="dateBar">
<img src="/s.gif" alt="Previous Month"  class="calLeft" onblur="this.className = 'calLeft';" onclick="DatePicker.datePicker.prevMonth();" onfocus="this.className = 'calLeftOn';" onmouseout="this.className = 'calLeft';" onmouseover="this.className = 'calLeftOn';" title="Previous Month"/>
<select  id="calMonthPicker" name="calMonthPicker" title="Month">
    <option value="0">January</option>
    <option value="1">February</option>
    <option value="2">March</option>
    <option value="3">April</option>
    <option value="4">May</option>
    <option value="5">June</option>
    <option value="6">July</option>
    <option value="7">August</option>
    <option value="8">September</option>
    <option value="9">October</option>
    <option value="10">November</option>
    <option value="11">December</option>
</select>
<img src="/s.gif" alt="Next Month"  class="calRight" onblur="this.className = 'calRight';" onclick="DatePicker.datePicker.nextMonth();" onfocus="this.className = 'calRightOn';" onmouseout="this.className = 'calRight';" onmouseover="this.className = 'calRightOn';" title="Next Month"/><select  id="calYearPicker" name="calYearPicker" title="Year">
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
    <option value="2020">2020</option>
    <option value="2021">2021</option>
</select>
</div>
<div class="calBody">
<table  class="calDays" border="0" cellpadding="0" cellspacing="0" id="datePickerCalendar"><tr><TH class="dayOfWeek" scope="col">Sun</TH><TH class="dayOfWeek" scope="col">Mon</TH><TH class="dayOfWeek" scope="col">Tue</TH><TH class="dayOfWeek" scope="col">Wed</TH><TH class="dayOfWeek" scope="col">Thu</TH><TH class="dayOfWeek" scope="col">Fri</TH><TH class="dayOfWeek" scope="col">Sat</TH></tr>
<tr class="calRow" id="calRow1"><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td></tr>
<tr class="calRow" id="calRow2"><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td></tr>
<tr class="calRow" id="calRow3"><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td></tr>
<tr class="calRow" id="calRow4"><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td></tr>
<tr class="calRow" id="calRow5"><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td></tr>
<tr class="calRow" id="calRow6"><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td><td onblur="hiOff(this);" onclick="DatePicker.datePicker.selectDate(this);" onfocus="hiOn(this);" onmouseout="hiOff(this);" onmouseover="hiOn(this);">&nbsp;</td></tr>
</table>
<div class="buttonBar">
    <a href="javascript&colon;%20void%280%29%3B" class="calToday" onclick="DatePicker.datePicker.selectDate('today');return false;">Today</a>
</div>
</div>
</div>
  </apex:pageBlockSection>       
    

</apex:pageBlock>
</apex:form>

<script>
function CheckDiv()
    {
    
   document.getElementById("Recurrencediv").style.display='block';
   document.getElementById("Daily").style.display='block';
   


}  
</script>

</apex:page>




 
ClintLeeClintLee
Hi Minky,

In the constructor of your controller you need to assign the Task to the ta variable.

Your constructor should look like this:
 
public LatestTask(ApexPages.StandardController controller) 
{
    ta = (Task) controller.getRecord();
    ta.OwnerId = UserInfo.getUserId();
}



 
ClintLeeClintLee
Your save method should be like this:
 
public PageReference save()
{
    PageReference returnPage = null;
    
    try {
        update ta;
        returnPage = new PageReference('/' + ta.Id);
    } catch(Exception e) {
        
    }

    return returnPage;
}
On your visualforce page change the inputFields where you reference task to ta.
 
Minky VaidMinky Vaid
hi Clintlee

Thank you for reply! I tried above code, its working fine with assigned to current user but still not saving the task.
Please see my code below for apex class. May be I am missing something Could you please advice
public class LatestTask1 {public Task ta{get;set;}

    public LatestTask1(ApexPages.StandardController controller) 
{
    ta = (Task) controller.getRecord();
    ta.OwnerId = UserInfo.getUserId();
}
    
  public Attachment file;
        public Attachment getfile(){
            file = new Attachment();
            return file;
        }
        public PageReference saveattachment(){
            string recordid = System.currentPageReference().getParameters().get('id');
            Attachment attach = new Attachment(
                parentid = recordid,
                name = file.name,
                body = file.body);
            insert attach;
            return null;
        }
   
    
 public void Cancel() 
  { 
  }    
  public void SaveNewEvent()
  {           
  } 
  public void SaveNewTask() 
  {            
  }    
  public PageReference save()
{
    PageReference returnPage = null;
    
    try {
        update ta;
        returnPage = new PageReference('/' + ta.Id);
    } catch(Exception e) {
        
    }

    return returnPage;
}
}


 
ClintLeeClintLee
Your save method should either save the task and return you to the detail page for the task or, if an error is thrown when saving the task, you would remain on the visualforce page.

What happens when you try to save?  Are you returned to the detail page for the task?

I would add the following to Line 42 of your controller within the catch block. This way you can review the logs to see if an exception is being thrown thus preventing the task from being saved.
 
System.debug('Error saving task: ' + e.getMessage()):