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
Niharika GoudNiharika Goud 

How to Display Exam Question Paper Using VisualForce Pages

Hai

I am New To SFDC

Please Help me Any One....
NagendraNagendra (Salesforce Developers) 
Hi Niharika,

Please find the sample code below and tweak it as per your requirement which might help you.
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.id),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 a 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.

Hope this helps.

Thanks,
Nagendra
 
Robert Griffin 3Robert Griffin 3
I am so happy that my exams are over. But there is an equally difficult stage ahead - this is the search for a job and the preparation of the necessary documents for the interview. I found a service https://www.lorservice.com/ that will help me prepare a letter of recommendation. I did not dare to write it myself so as not to make mistakes and not reduce my chances of finding a job.
Theo SandersTheo Sanders
Hello! Our college paper writer (https://www.masterpapers.com/) may feel the need to delegate this essay to a writer with experience writing them, with the intention of retaining their grade. So, when choosing professionals to write an essay, you need to make sure that they can provide original work.