7

Having a little issue. Trying to insert a task using a custom controller, and I am not getting any kind of "error" when this executes. Everything else on the page seems to work but this.

Any help would be great. Thanks. Also I have taken out any fields that would be pulled from the page and tried to just test it by entering the variables and it didn't work.

 public List<Task> tasks {get; set;}
 public ID CurrentAcct = Apexpages.CurrentPage().getParameters().get('Id');
 public ID CurrentUser = UserInfo.getUserId();
 private String soql {get;set;}
 private ApexPages.StandardController stdController;
 private Account_Plan__c AcctObj;
 private Task Ntask;


 //Other Code here for queries and constructor


   Public Pagereference AddTask(){
    String taskdate = Apexpages.CurrentPage().GetParameters().get('tdate');
    Date d = date.parse(taskdate);
    Ntask = new Task();
    Ntask.ActivityDate = date.parse('5/25/13');
    Ntask.Subject = 'This is a test';
    Ntask.OwnerId = CurrentUser;
    Ntask.WhatId = CurrentAcct;
    Ntask.Status = 'In Progress';
    Ntask.Priority = 'Normal';
    Ntask.Type = 'Call';


    try{
    insert Ntask;}
    catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'There was an Error! Cannot Create Task'));
    } 

    return null;
    }
10
  • 2
    Should you be inserting Ntask, rather than t?
    – Doug B
    May 3, 2013 at 14:04
  • Yes. Sorry. I forgot to change that when I did a copy and paste from my Notepad
    – AlphaBravo
    May 3, 2013 at 14:30
  • 1
    So no errors but the task isn't created? How are CurrentUser and CurrentAcct populated? Can you add that code?
    – Mike Chale
    May 3, 2013 at 14:37
  • 2
    Sounds silly, but are you sure the method is being called from the page? Try adding a pagemessage inside the try to show that the code is running.
    – Doug B
    May 3, 2013 at 14:52
  • 1
    instead of return null, if there are no errors, return the task record. try{ insert Ntask; return new ApexPages.pagereference('/' + ntask.Id);} catch (Exception e) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'There was an Error! Cannot Create Task'));return null; } Also in your Page make sure you use <apex:pageMessages/> tag to display errors. May 3, 2013 at 20:50

1 Answer 1

0

Two suggestions:

1) Ensure that you are rerendering the apex:pageMessages block of your vf page from the command button which is executing the AddTask method.
2) As suggested by CoryCowgill instead of return null; use return new pageReference('/'+Ntask.Id);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .