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
JackMckracken83JackMckracken83 

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?

AmitSahuAmitSahu

Can you post your code..?

JackMckracken83JackMckracken83

---------Controller

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();
rq.reflectionResponses__r.add(resp);
refQs.add(new reflectionQuestion__c(Id=rq.Id, questionText__c=rq.questionText__c));
System.debug(rq.reflectionResponses__r.size());
}
}
}
return refQs;
}

 

----------View

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