function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SalesforceLearnerNewbieSalesforceLearnerNewbie 

User tick on the correct output and then these output will be stored in task

I wish to create radiobutton that could allow user to click on the correct output shown on vf page. 


Example, 

Output 1: Do Many things  *radiobutton*
Output 2: Do Nothing *radiobutton*
Output 3: Do something for myself *radiobutton*

When the user choose tick output 1 or any other output, these ticked outputs will be stored in task. 

My attempt for VF page:

                                        <apex:selectRadio id="subject" value="{!subject}" size="1" > 
                                        <apex:selectoption itemLabel="{!td}" itemValue="{!td}"></apex:selectoption>
                                        </apex:selectRadio>


My attempt for Apex controller:

String userId = UserInfo.getUserId();
    
    Task t = new Task();
    t.OwnerId = userId;
    t.Subject = subject;
    t.Status = 'Open';
    t.Priority = 'Normal';    
    insert t;
    
How should I modify my code in order for it to have the buttons that can be clicked and after clicking it, the value relevant to the output will be stored as our subject? 
Vishal_GuptaVishal_Gupta
Hello,

Please use the below code : 
<apex:page controller="CreateTasks">
    <Apex:form>
        <Apex:pageBlock>
            <Apex:selectRadio value="{!subject}">
                <apex:selectOption itemValue="Do Nothing" itemLabel="Do Nothing"></apex:selectOption>
                <apex:selectOption itemValue="Do Many Thing" itemLabel="Do Many Thing"></apex:selectOption>
                <apex:selectOption itemValue="Do Something" itemLabel="Do Something"></apex:selectOption>
                <apex:actionSupport event="onchange" action="{!changedOption}" reRender="test" />
            </Apex:selectRadio>
        </Apex:pageBlock>
    </Apex:form>
</apex:page>
 
public class CreateTasks
{
   
    public String subject{get;set;}
    public CreateTasks()
    {
        subject = 'None';
    }
    
    
    public void changedOption()
    {
        String userId = UserInfo.getUserId();
    
        Task t = new Task();
        t.OwnerId = userId;
        t.Subject = subject;
        t.Status = 'Open';
        t.Priority = 'Normal';    
        insert t;
    }
}

Please let me know if its answers your question.

 
SalesforceLearnerNewbieSalesforceLearnerNewbie

Hi, 
 
Thank you so much for your response. I have tried the solution you provided but somehow when I try to perform it this method;

Eg. I append the outputs into a 2D-list. List<List<String>> output in my controller. 

Then in my vf page code:

                 <apex:repeat value="{!IF((index< listtodotemp.size),output[index],false)}" var="o">

                            <apex:pageBlockSection columns="1">
                                <apex:selectRadio value="{!subject}" >
                                    <apex:selectOption itemValue="{!o}" itemlabel="{!o}"/>
                                    <apex:actionSupport event="onchange" action="{!taskInsert}" reRender="test" />
                                </apex:selectRadio>
                            </apex:pageBlockSection>
                 </repeat>

My page shows exactly what I wanted it to be:

*radiobutton* Do Many things 
*radiobutton* Do Nothing 
*radiobutton* Do something for myself 

And after applying your code, 

Controller:
public with sharing class all_controller {

    public calloutViewer_Controller(ApexPages.StandardController controller){
            subject = 'None';
    }

    public PageReference taskInsert() {


    String userId = UserInfo.getUserId();
    
       Task t = new Task();
        t.OwnerId = userId;
        t.Subject = subject;
         t.Status = 'Open';
         t.Priority = 'Normal';    
         insert t;
 

 

........ until end.

 

Problem, when I choose 2 or 3 radiobutton and tick it, i received an error about "Value is not valid. ". Do you know why?