You need to sign in to do that
Don't have an account?
David9133
Handling the radiobutton value and selected record id in salesforce
I want to capture both the Record Id and the selected Radio Button value and pass it to the controller and create new Child object record with the selected values only process the selected records.
Visualforce Code:
<apex:page controller="skillproficiencycontroller" >
<apex:form >
<script> function myFunction( val){ var x = val.value; callfunc(x); } </script>
<apex:pageBlock > <
apex:pageblockTable value="{!skilllist}" var="s">
<apex:column value="{!s.Name}"/>
<apex:column headerValue="Proficiency">
<apex:selectRadio value="{!Selected}" onclick="myFunction(this);">
<apex:selectOptions value="{!items}" /> </apex:selectRadio>
</apex:column>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public with sharing class skillproficiencycontroller
{
public List<skill__c> skilllist{get;set;}
public String Selected{get;set;}
public skillproficiencycontroller()
{
skilllist = new List<Skill__c>();
skilllist= [select Name FROM skill__c];
}
public List<selectoption> getitems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Basic Knowledge' , 'Basic Knowledge'));
options.add(new SelectOption('Intermediate' , 'Intermediate'));
options.add(new SelectOption('Advanced' , 'Advanced'));
return options;
}
public void Save()
{
List<Skill_Details__c >skilldetailslist = new List<Skill_Details__c >();
for(Skill s: selectedskilllist){
Skill_Details__c sd = new Skill_Details__c();
sd.Skill_c = s.Id;
sd.Proficiency__c = Selectedvalue;
skilldetailslist.add(sd);
}
Insert skilldetailslist;
}
}}
View Screenshot
Visualforce Code:
<apex:page controller="skillproficiencycontroller" >
<apex:form >
<script> function myFunction( val){ var x = val.value; callfunc(x); } </script>
<apex:pageBlock > <
apex:pageblockTable value="{!skilllist}" var="s">
<apex:column value="{!s.Name}"/>
<apex:column headerValue="Proficiency">
<apex:selectRadio value="{!Selected}" onclick="myFunction(this);">
<apex:selectOptions value="{!items}" /> </apex:selectRadio>
</apex:column>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public with sharing class skillproficiencycontroller
{
public List<skill__c> skilllist{get;set;}
public String Selected{get;set;}
public skillproficiencycontroller()
{
skilllist = new List<Skill__c>();
skilllist= [select Name FROM skill__c];
}
public List<selectoption> getitems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Basic Knowledge' , 'Basic Knowledge'));
options.add(new SelectOption('Intermediate' , 'Intermediate'));
options.add(new SelectOption('Advanced' , 'Advanced'));
return options;
}
public void Save()
{
List<Skill_Details__c >skilldetailslist = new List<Skill_Details__c >();
for(Skill s: selectedskilllist){
Skill_Details__c sd = new Skill_Details__c();
sd.Skill_c = s.Id;
sd.Proficiency__c = Selectedvalue;
skilldetailslist.add(sd);
}
Insert skilldetailslist;
}
}}
View Screenshot
First and foremost sincerely regret the delayed reply.
Please find the below solution for your requirement.
This is a perfect use case for a wrapper class(https://developer.salesforce.com/page/Wrapper_Class). The wrapper class will contain the sObject which was originally queried and the value chosen in the related selectRadio, which you can reference during your save method after checking to see if the user made a selection.
Apex Controller: Visual Force Page: Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue and becomes a proper solution which results in helping others who are really in need of it.
Best Regards,
Nagendra.P