I try to make list via apex & visualforce, it can create task under selected record in that pages. The idea is to create task from that list so user can easily create an activity related to selected record.

But i have a problem, the task is created on the selected record but somehow type and description is not filled. Can you please help me to solved this ?

Here is the page: visualforce

Visualforce Code

<apex:pageBlock title="Signed Up Opportunity List" id="signedOpportunityList">
        <apex:pageMessages escape="false"></apex:pageMessages>        
            <apex:pageBlockTable var="oppList" value="{!signedUpOpp}">
                <apex:column headerValue="Opportunity Name">
                    <apex:outputLink value="/{!oppList.Id}">{!oppList.Name}</apex:outputLink>
                <apex:column headerValue="Contact Name">
                    <apex:repeat value="{!oppList.OpportunityContactRoles}" var="con">                    
                        <apex:outputLink value="/{!con.Contact.Id}">{!con.Contact.Name}</apex:outputLink>                       
                <apex:column headerValue="Contact Phone">
                    <apex:repeat value="{!oppList.OpportunityContactRoles}" var="con">                    
                        <apex:outputText value="{!con.Contact.Phone}"/>                       
                <apex:column headerValue="Contact Email">
                    <apex:repeat value="{!oppList.OpportunityContactRoles}" var="con">                    
                        <apex:outputLink value="mailto:{!con.Contact.Email}">{!con.Contact.Email}</apex:outputLink>                       
                <apex:column headerValue="Account Number">
                    <apex:outputField value="{!oppList.Account_Number__c}"/>
                <apex:column headerValue="Est. Outstanding Amount">
                    <apex:outputField value="{!oppList.Estimated_Outstanding_Amount__c}"/>
                <apex:column headerValue="Stage">
                    <apex:outputField value="{!oppList.StageName}"/>
                <apex:column headerValue="Last Actvity Date">
                    <apex:outputField value="{!oppList.LastActivityDate}"/>
                <apex:column headerValue="Description">
                    <apex:inputtextarea value="{!taskComment}" />
                <apex:column headerValue="Type">
                    <apex:selectList value="{!taskType}" multiselect="false" size="1">
                        <apex:selectOption itemValue="Reached Call" itemLabel="Reached Call"/>
                        <apex:selectOption itemValue="Unreached Call" itemLabel="Unreached Call"/>
                        <apex:selectOption itemValue="Email" itemLabel="Email"/>  
                        <apex:selectOption itemValue="Meeting" itemLabel="Meeting"/>
                        <apex:selectOption itemValue="Whatsapp" itemLabel="Whatsapp"/>
                        <apex:selectOption itemValue="Other" itemLabel="Other"/>                            
                <apex:column style="text-align:center">
                            <!-- command button in a column... neato -->
                            <apex:commandButton value="Save Task" action="{!createTask}" rerender="signedOpportunityList" status="actStatusId" styleClass="buttonGo">
                                <!-- again we use apex:param to be able to tell the controller which row we are working with -->
                                <apex:param value="{!oppList.Id}" assignTo="{!toSelect}" name="toSelect"/>
            <apex:pageBlockButtons >
                <apex:commandButton value="Refresh" reRender="signedOpportunityList" action="{!Refresh}" status="actStatusId"/>

Apex Code

public Task prospectTask;
public String taskType {get;set;}
public String taskComment {get;set;}    
public leadListView() {
public leadListView(ApexPages.StandardController controller) { 
        signedUpOpp = [SELECT (SELECT Contact.Name,Contact.Id,Contact.Phone,Contact.Email FROM OpportunityContactRoles WHERE IsPrimary=true LIMIT 1),Account_Number__c,Estimated_Outstanding_Amount__c,Contact__r.Name,Contact__r.Id,LastActivityDate,Name, Account.Name,Account.id, StageName, Amount FROM Opportunity WHERE Account.Sign_Up__c = true AND (StageName != 'Prospecting' AND StageName != 'Postponed') AND OwnerId = :UserInfo.getUserId() AND IsClosed = false ORDER BY LastActivityDate LIMIT 10];        

public void createTask(){
    prospectTask = new Task();
    prospectTask.Type = taskType;
    prospectTask.Subject = taskType;
    prospectTask.Description = taskComment;
    prospectTask.whatId = toSelect;
    prospectTask.ActivityDate = system.today();    
    insert prospectTask;
  • Does user has access to these fields? Can you add some debug statement inside createTask method for variables "taskType" and "taskComment"?
    – Devendra
    Oct 12, 2016 at 11:29

1 Answer 1


I think you should use a wrapper and wrap a fresh instance of task with each record in the row.

It wont work this way as the row would override the value please try using a wrapper and let me know if there is any problem.

You must log in to answer this question.

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