+ Start a Discussion

Quiz-type functionality

I've got a quiz-type application built. I set up a question object and a question response object, the response obv being a child of the question. I've managed to build a page that renders out the questions and a textbox for each so the user can type in an answer. The portion that's giving me a really hard time is trying to save the user's responses. Seems like this should be REALLY simple, but I've been going round and round. Basically I'm trying to instantiate a new response object for each question when the page loads, then have a value from a textbox for each question assigned to a field in the response object and saved. My problem is what variable to assign to the textboxes? Shouldn't I be able to add a new response object to each question's response collection when the page loads, assign the text of each response to the variable of the textbox, and then loop through and save each response? This seems like really common functionality - does anyone know of an example that they can point me to?


Can you post your code..?



public List<reflectionQuestion__c> getReflectionQuestions(){
Id id = System.currentPageReference().getParameters().get('id');

if(refQs == null) {
refQs = new List<reflectionQuestion__c>();

for(observationVideo__c vid : [SELECT Id, (SELECT Id, questionText__c FROM reflectionQuestions__r) FROM observationVideo__c WHERE Id = :id]) {
for(reflectionQuestion__c rq : vid.reflectionQuestions__r) {
reflectionResponse__c resp = new reflectionResponse__c();
refQs.add(new reflectionQuestion__c(Id=rq.Id, questionText__c=rq.questionText__c));
return refQs;



<apex:form >
<apex:repeat value="{!reflectionQuestions}" var="r">
<apex:repeat value="{!r.reflectionResponses__r}" var="resp">
<apex:inputTextarea style="width: 600px; height: 200px" value="{!resp.responseText__c}"/>
<apex:commandButton action="{!saveReflection}" value="Save"/>