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

First Big VisualForce Project.. HELP!

Hey all, I am ramping up to start my first big visualforce project. I think it's not terribly complicated, but I could still use some design tips. Basically what we are trying to build is simple survey tool. I have 3 objects involved.


1) Contact

2) Question__c

3) Question_Answer__c


Question has 6 fields:


Linked_field (text field)

Picklist_Values (text area)

Question_Name (text field)

Question_text (text area)

Question_Type (pickilist)


Question Answer has 3 fields:

Contact (Lookup to contact)

Question(Lookup to question)

Answer (text field)


What I want to happen is to host a visualforce page through Salesforce sites. The page invokes a controller that finds some random questionthis contact has not yet answered (defined as: no Question_answer__c record exists for this contact for this question__c), and presents them the question_text, and a fitting method of answering the question based on the question_type found in the related Question__C object. Once the question is answered, a Question_answer__c record is created and saved with the provided information. Then another question is picked at random that the user has not answered and the cycle repeats until all questions are answered, or the user stops.


So my questions are

1) Should I write a custom controller, or just extend one? Mostly this revolves around a Question__c object, because that contains all the information required for creating the question. Not sure exactly though, this being my first one and all.

2) How can I pick a record at random, that the user has NOT answered before? I imagine some kind of SOQL outer join type deal but the exact method for doing this escapes me.

3) Any clever ideas how I can create my dynamic answer__c field? This will probably be the hardest part. For example, if the qustion is a picklist (as specified in the question_type__c field on the question__c object), it needs create a piclist field, and populate it with the picklist_values field from the question__c object. If it is specified as a text field, it needs to render as a text field, etc.


4) Ideally the visualforce page could take the ID of a specific question to answer and it will grab that question instead of grabbing a random one. That should be pretty easy, just making note of it here so I remember :P


5) Kind of a side bar thing that will probably be handled later, but worth asking. Does anyone know if Salesforce sites offers the equivilent of session variables? I am going to need to write a login system eventually, so a contact can login with their username and password, and then begin answering questions. For now I'll probably just pass the contactId around in the URL so I know which contact to create the question_answer__c objects for, but eventually I'd like to move to something more secure.


Thanks for any insight. I really appreciate it!


Look at SurveyShark and Survey Force on Code Share for some sample Survey implementations. That should give you and idea of how best to architect your requirement.


Thanks for the reply. As with almost all available software it's likely dramatically over engineered and complciated to disect, but I'll give it a whack.


I don't have any VF advice for you, but from a design standpoint you might want to track Unanswered Questions rather than Answered Questions.  The user starts with all questions unanswered, so its much easier to pick at random from the list, and flag the row as Answered as the user goes along.


Probably best to consider the object as Assigned Questions rather than answered/unanswered and use an Answered checkbox field.