3

I have a requirement from my client saying that, set of questions should be populated in Task based on some criteria given by the customer. For example On creating a Task for an Account, then the account automatically will be pull in all the relevant questions in the Task.Before that we need to store the set of questions in Salesforce. Kindly give me some idea to achieve this. Thanks in advance

Updated my question: Apex code:

public class ListQuestions
{
    public List<ListTaskQuestions__c> Questions {get;set;}

   public ListQuestions()
   {
                          //    ListTaskQuestions__c[] allQuestions = [select Question1__c,Question2__c from ListTaskQuestions__c ];
       Map<String,ListTaskQuestions__c> allQuestions = ListTaskQuestions__c.getAll();
        Questions= allQuestions.values();
   } 

}

Vf page:

<apex:page Controller="ListQuestions" sidebar="false" >
<apex:form >
    <apex:pageblock >
        <apex:pageblockTable value="{!Questions}" var="q">
            <apex:column value="{!q.Question1__c}"/>       
            <apex:column value="{!q.Question2__c}"/>
        </apex:pageblockTable>
    </apex:pageblock>
</apex:form>
</apex:page>

Regards, Lavanya.

1 Answer 1

2

Here is one approach...

Store the set of questions in a normal custom object that you can then relate to the Account or store them in a list custom setting.

If there is a maximum number of questions of say 10, add 10 text custom fields to Task (Activity) to hold copies of the relevant questions (that are set read-only in the Task page layout) and 10 text custom fields for the users to enter their answers (that are left editable). Note that this approach does not allow the answers to be of various types e.g. checkbox, date etc and unless the number of questions is always fixed you can't make the answers required.

(Alternatively you could just format the Tasks's Description field to list the questions and include prompts for the answers so that the user can answer by editing the Descriptions.)

If you are creating the Task from Apex code, you populate the questions as you create the Task. If users are creating the Task through the normal UI "new" button, then you add a trigger that uses the Tasks's WhatId and/or WhoId to find the object the Task is related to and then populate the relevant questions in the trigger.

Update - Using List Custom Settings

Create a custom setting using “New” of "Setting Type" of "List" and "Visibility" of "Public" called "Question" that has a 255 character text field called "Text". You can then “Manage” that list custom setting and add your questions to it; you will also have to give each question a unique "Name". You can use “Create New View” to conveniently see all the entries.

Then in your code you can get a list of all the questions (and therefore can access the Text__c fields) using:

Question__c[] questions = Question__c.getAll();

To control ordering, you could add a numeric "Sequence" field that you set via "Manage" to 1, 2, 3 etc. and in that case it is better to use SOQL to access the questions so you can get them in the correct order e.g.:

Question__c[] questions = [select Text__c from Question__c order by Sequence__c];

Please Google for further examples and information.

5
  • Thanks for your reply. It is very useful for me. Fist option is suitable for us. Can you please provide some more information regarding list custom setting to achieve this. Commented Nov 6, 2013 at 5:04
  • Added info to the answer.
    – Keith C
    Commented Nov 6, 2013 at 9:21
  • You are welcome. The normal way to recognise when an answer is useful on this site is to accept their answer and give the answer a "This answer is useful" vote.
    – Keith C
    Commented Nov 6, 2013 at 12:34
  • Thanks for a lot for your reply. I have updated my question.Its working correctly for vf tab but need to display this in custom button. I have searched in google didn't get any idea.Please provide some more informaiton regarding this. Commented Nov 7, 2013 at 6:22
  • Your code suggests that you have put more than one question in each list custom setting entry which seems strange; I would have expected one question in each. I don't really understand what you mean by "in a button". I suggest you add a separate question so you can be clearer.
    – Keith C
    Commented Nov 7, 2013 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .