You need to sign in to do that
Don't have an account?
Vijay Kumar Rebbala 11
How can i save multiple input checkbox values for multiple records from vfp and insert the data as child records.
Multiple records from Student__c are shown on VFP with inputcheckbox. I want to save the input checkbox values and the Student__c Id's in child records.
//VFP: <apex:page controller="Testctrl"> <apex:form > <apex:repeat value="{!acctlist}" var="accs" > <apex:outputText value="{!accs.Name}"></apex:outputText> <apex:inputCheckbox value="{!input}" > </apex:inputCheckbox><br/> </apex:repeat> <apex:commandButton action="{!submit}" value="Submit"/> </apex:form> </apex:page> //CTRL: public class Testctrl { public list<Student__c> acctlist {get;set;} public list<Boolean> input {get;set;} public list<Id> stuids; public list<Attendence__c> attds = new list<Attendence__c>(); public Integer s; public Testctrl(){ system.debug('************checkbox_inputs*****************'+input); acctlist = [SELECT Id, Name FROM Student__c]; s = acctlist.size(); system.debug('*************recordcount****************'+s); system.debug('*************studentlist****************'+acctlist); for(Student__c stid: acctlist){ stuids.add(stid.id); } system.debug('************studentids*****************'+stuids); } public void submit(){ for(Integer i=0;i<s;i++){ attds.add(new Attendence__c(Absent__c = input[i], Student__c = stuids[i])); } system.debug('************attendence*****************'+attds); insert attds; }
Refer the below snippet.
VF page
Apex class
Kindly mark it as an answer if that works for you.
All Answers
Refer the below snippet.
VF page
Apex class
Kindly mark it as an answer if that works for you.
This is a case for our old friend, the wrapper class. There's an example of using this on my blog at:
http://bobbuzzard.blogspot.co.uk/2011/07/managing-list-of-new-records-in.html
It doesn't exactly match your use case, but should give you a grounding in the concept. So in your case you would have a wrapper class that would contain the Student__c record and the Boolean to capture the checkbox. You iterate a list of these in your apex:repeat, and when the user clicks save the wrapper class instance will contain the Student__c record and the user's selection for the checkbox, which you can use to create a child record.
Error is in expression '{!submit}' in component <apex:commandButton> in page testpage: Class.Testctrl.submit: line 44, column 1".
@bob_buzzard, Thanks for you reply. Looking into your blog.
Hi Vijay,
You either need to mark "Date of Attendence" as not required in the data model OR provide a value to that field before inserting the "attds" records in the apex code.