0

I have a list of questions (150+). Each question has a particular type of answer and some of the answers can be picklists. Now I want to create the response picklists based on the question, how can I do so? I do not want the question to be a controlling picklist, as the number of questions can grow further.

Thanks for the help in advance.

Example 
Ques                      Response Type                         Value
What is your fav game?    Picklist                              Chess, Tennis, Checkers
What is your fav colour?  Picklist                              Red,Green,Blue, Yellow
Which is your fav food?   Picklist                              Indian, Chinese, Italian, Mexican

So I need to populate the picklist values based on the questions. I have more than 150 questions. So making the question controlling picklist and the Value as dependent picklist does not seem to be a suitable solution. How can I achieve this functionality?

  • "Now I want to create the response picklists based on the question, how can I do so?" This part of your question is not clear to me. Could you update your question with an example of how it should work? And also pls specify how you have implemented this in Salesforce (objects/fields/etc). – Guy Clairbois Aug 11 '14 at 12:57
1

This will depend on your archetecture of the question record and your answers.

Lets assume the Object that holds your questions also holds the answers. You can also do this by having an answers object that has a MD relationship to the question object and iterate over those to build the lists.

As an example:

Question Object -> Question_Field__c, Answer_Field__c (Text), isPicklist__c

Then in your controller you populate your answers into the variable you define...

To populate the pick list for the questions with an isPicklist__c = true you would create a method to get the answers as a pick list:

public SelectOption[] populate_Answers(Question__c q){

    String[] tmp = q.Answer_Field__c.split(';');
    SelectOption[] ans = New SelectOption[]{};

    for(String a : tmp){
        ans.add(New SelectOption(a,a));
    }

    return ans;

}

Now, how you use this or populate it on your page you will need to figure out. A wrapper class may be necessary as well as conditional rendering on the VF page to either show a pick list, value, true false, etc.

  • This gives me some idea. Thanks. I am also thinking of keeping the question and response as two diff objects. – ParoTech Aug 11 '14 at 14:26
0

You can do this in VisualForce. Create your various picklists, but write the getter functions for the dependent ones so that they return lists (of SelectOptions) based on the previous inputs. Make sure that you also have the dependent components rerender the picklists whenever they are changed.

  • I am pretty new to Salesforce. Can you please provide a link which has a small example similar to this I can follow. – ParoTech Aug 11 '14 at 13:29
0

Maybe I'm thinking too simple but why not make each question a custom field on the questionnaire object, each with their appropriate type (e.g. text, picklist, etc).

In order to show particular questions for particular questionnaires, use recordtypes with dedicated page layouts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.