4

I am creating a visual force page where a user can log a completed task and set up a new one. I'd like to set default values for the Status to New for one section and Complete for the other. Is there a way that I can do this with my controller extension?

Below is the updated code setting two instances:

VF Page:

    <apex:page standardController="Task" extensions="TaskSubjectextension">
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockButtons location="top">
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection title="Information">
        <apex:repeat value="{!$ObjectType.Task.FieldSets.LogCallTaskInfo}" var="info">
            <apex:inputField value="{!logMyTask[info]}"/>
        </apex:repeat>
    </apex:pageBlockSection>
     <apex:pageBlockSection title="Schedule Follow-Up Task">
        <apex:repeat value="{!$ObjectType.Task.FieldSets.FollowUpTask}" var="followup">
            <apex:inputField value="{!setNewTask[followup]}"/>
        </apex:repeat>
    </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>    

</apex:page>

Extension:

public with sharing class TaskSubjectextension {

public Task logmyTask              {get;set;}
public Task setnewTask              {get;set;}    
public User currentuser         {get;set;}      

    public TaskSubjectextension(ApexPages.StandardController controller) {
        this.logmyTask = (Task)controller.getRecord();
        this.setnewTask = new Task();
        currentuser=new User();
        currentuser=[Select Id,Name,Email from User where Id=:userinfo.getuserId()];
        logmyTask.Subject = 'Call';
        logmyTask.OwnerID = currentuser.Id;
        logmyTask.Status = 'Completed';
        setnewTask.Subject = 'Call';
        setnewTask.OwnerID = currentuser.Id;
        setnewTask.Status = 'New';

    }

}

1 Answer 1

4

I don't think it would be possible with one instance of task. You need to create two separate instance or need to use a list.

public Task OldmyTask              {get;set;}
public Task NewmyTask              {get;set;}

VF Page

<apex:pageBlockSection title="Information">
    <apex:repeat value="{!$ObjectType.Task.FieldSets.LogCallTaskInfo}" var="info">
        <apex:inputField value="{!OldmyTask[info]}"/>
    </apex:repeat>
</apex:pageBlockSection>
 <apex:pageBlockSection title="Schedule Follow-Up Task">
    <apex:repeat value="{!$ObjectType.Task.FieldSets.FollowUpTask}" var="followup">
        <apex:inputField value="{!NewmyTask[followup]}"/>
    </apex:repeat>
     <apex:inputField value="{!NewmyTask.Status}"/>
</apex:pageBlockSection>
2
  • I don't see that adding the separate instances, actually changes the value of the status. On initial load they are both showing the same? Commented Sep 13, 2016 at 22:56
  • 1
    This works, just needed to set one of the instances to new within the method. Thanks for the help! Commented Sep 13, 2016 at 23:07

You must log in to answer this question.

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