You need to sign in to do that
Don't have an account?
sravan alaparthi
assign a account to task.what
Hi i have to assign a task on the account selected by the user,i am stuck in between any help would be great
Page:
<apex:page controller="PractiseController"> <apex:form > <apex:pageBlock > <apex:pageBlockSection columns="1"> <apex:selectList size="1" value="{!selectValue}" label="Related to" onclick=""> <apex:selectOptions value="{!Options}"></apex:selectOptions> </apex:selectList> <apex:inputTextarea value="{!comments}" label="Comments" /> <apex:commandButton value="Done" action="{!assignTask}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Sravan Alaparthi
Controller:
public with sharing class PractiseController{ public List<SelectOption> options=new List<Selectoption>(); public Id selectValue { get;set; } public string comments { get;set; } //method to generate account names as picklist public List<SelectOption> getOptions(){ for(Account account:[Select ID,Name from Account]){ options.add(new SelectOption(account.id,account.Name));} return options; } //method to assign a task public pageReference assignTask(){ Task lt=new Task(); lt.what=//assign selected account to task lt.Description=comments; pageReference pr=new pageReference('/'+selectvalue); return pr; } }
Place the insert in a try catch statement.
try(
insert lt;
{
catch(DMLException e){
System.debug('DMLException:' + e);
}
Turn on debug logs in the salesforce web ui. Try again and check the logs. Or run your unit test and check the debug log. Do a search for the string in the debug method and the error message of why will be displayed.
All Answers
lt.WhatId = selectValue;
Hi Andrew,
Thanks for the reply,actually the problem was...
everything works fine even the page is redirected to account detail page,but the task is not inserted...
Place the insert in a try catch statement.
try(
insert lt;
{
catch(DMLException e){
System.debug('DMLException:' + e);
}
Turn on debug logs in the salesforce web ui. Try again and check the logs. Or run your unit test and check the debug log. Do a search for the string in the debug method and the error message of why will be displayed.