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


Hi,i am having questions__c(parent) and answers__c(child) are 2 custom objects which are having MDR relation.
Need to create ONLINE EXAM on vf page.i have 1000 records in questions__c object .i need to fetch records from questions__c. randomly to vf page and need to show different questions which should not repeat.
question =60. no question should repeat for a single participant.
Can any one make me out from this???

Thanx in advance...!!!


You could do something like this:


public class examcontroller {
	public examcontroller() {
		question__c[] options = [select id,name,question__c,(select id,name,answer__c from answers__r) from question__c where active__c = true limit 1,000];
		examitems = new examitem[0];
		while(!options.isempty() && examitems.size() < 60) {
			examitems.add(new examitem(options.remove(math.mod(crypo.getrandominteger(),options.size()))));
	public examitem[] examitems { get; set; }
	public class examitem {
		public question__c question { get; set; }
		public id selectedanswer { get; set; }
		public selectoption[] getansweroptions {
			selectoption[] options = new selectoption[] { new selectoption('','-- Choose --') };
			for(answer__c answer:question.answers__r) {
				options.add(new selectoption(string.valueof(,answer.answer__c));
			return options;
		public examitem(question__c question) {
			this.question = question;
	public PageReference saveExam() {
		// I leave this as an exercise to the reader.
		return null;

You see, I query all available questions (using a flag to show only active questions), then i pick 60 of them by random number, removing them from the list so I guarantee they will be unique. The answers are generated as picklist options on the fly. If you allow multiple exams per participant, you can further filter the query with an anti-join so they will not receive questions they have saved answers to before.


Hi thanq for ur response..i created a back timer with a buttom start exam,but i need when i click on that button only the timer should start .but my button is not working....herz my code


Hi sir,Pleasure to meet u,,,i have the following code, i just created a back timer which is running good but its not working with button(start exam).please help me to create question paper in which 60 question will get by cliking NEXT--- NEXT in which it should not repeat the same one for each individual..,,


<apex:page sidebar="false" showHeader="false" controller="clsonline">
<body style="background-image:url('{!$Resource.Background}');">

<table border="1" cellpadding="14px" width="1200px" align="center" style= "font-size:25px; color: #686868 ;font-family:Verdana;">
<tr><th><center>SalesForce DEV-401 Examination</center></th></tr>
<table border="1" cellpadding="210px" width="1300px" style= "font-size:25px; color:#F00000 ;font-family:Verdana;">
<tr><td width="12%">


<td width="6px"> SALESFORCE<BR/><BR/><BR/>
<apex:pageBlock rendered="true" >


<script type="text/javascript">
var sec = 00; // set the seconds
var min = 60; // set the minutes

function countDown() {
if (sec == -01) {
sec = 59;
min = min - 1; }
else {
min = min; }

if (sec<=9) { sec = "0" + sec; }

time = (min<=9 ? "0" + min : min) + " min and " + sec + " sec ";

if (document.getElementById) { document.getElementById('theTime').innerHTML = time; }

SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
window.onload = countDown;


<style type="text/css">

.timeClass {
font-family:arial,verdana,helvetica,sans-serif, color:yellow;


<!-- This goes into the BODY of the file -->

<table width="100%">
<tr><td width="100%" align="center"><span id="theTime" class="timeClass"></span></td></tr>

<div id="mydiv"></div>
<center><input type= "button" id="button1" value="Start Exam" onclick="starttimer()" /></center>
</td><td width="22%">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <apex:image url="{!$Resource.pic}" width="80" height="50"/></td> </tr>
<table border="1" cellpadding="14px" width="1000px" align="center" style= "font-size:15px;color:#660000;font-family:Verdana;">
<th > <center><marquee behavior="alternate"> Cloud 2013.All Rights Reserved</marquee></center> </th>

chowdary marellachowdary marella

How to genereate random questions?am using the code below,but allowing dupes



Integer rand = Math.floor(Math.random()*14).intValue();

quess = new list<Questions__c>();
quess = [SELECT name,a__c,b__c,c__c,d__c FROM Questions__c limit 1 OFFSET :rand];



Also how can we store the answers and how to display as pdf after completion of exam????

chowdary marellachowdary marella

How can we store the result ?how can we differentiate which is right and wrong?


You don't seem to be making much of an effort to implement this yourself.  There will be a lot more interest in helping if you have a go and hit problems.  Simply posting up requirements smacks of asking us to write your code for free.


Helo sir,i am doing my i am begginer in coding.i was strucked , How not to repeat the random questions,also i used set

Manoj Kumar J 6Manoj Kumar J 6
Hi Marella,

 I have the same requirement can you post source of code