+ Start a Discussion
Nidhi Sharma 17Nidhi Sharma 17 

Relating values of 2 Text Area Fields

I have a VF page in a custom object consisting of 2 Text Area Field viz. 'Choose' and 'Weights'

In 'Choose' Text Area, I enter options:
a
b
c
d


And in 'Weights' Text Area, I enter options:

1
2
3
4

I want to relate one weight to one option. Say a-1, b-2, c-3, d-4

The code to seperate each field be:
 

private List<SelectOption> stringToSelectOptions(String str){
    List<String> strList = str.split('\\r|\n');
    List<SelectOption> returnVal = new List<SelectOption>();
    for(String s: strList){
      returnVal.add(new SelectOption(s,s));
    }
    return returnVal;
But now I am unable to link it to the previous 'Choose' field and display in the record.
Brenda S FinnBrenda S Finn
Hello

A few questions. Can you please provide the VF page where you are rendering these components. Also - I assume that a dependent picklist is not what you want? Are you wanting to change value of picklist field to be 'A-1' versus 1? Just trying to better understand your use case.
Nidhi Sharma 17Nidhi Sharma 17

Hi

I want new records to be created from these text areas such that for each record I have a field 'You chose option' (say a) and another field 'weight' (say 1); i.e. for both these text areas I want to have a new set of records in a new_custom_object related in the order of display.

Record 1: You chose option: a
               Weight: 1

Record 2: You chose option: b
               Weight: 2 and so on..

VF page
 

<apex:page standardcontroller="Survey__c" extensions="SurveyAndQuestionController" cache="false" sidebar="false" showheader="false" >

<apex:commandButton action="{!controllerSavQuestion}" value="{!$Label.LABS_SF_Save}"/>

-
-
-
</apex:page>

Apex Class
public Pagereference controllerSavQuestion(){
    if(questionReference == null || questionReference.length() <5){
      return saveNewQuestion();
    }
    else{ 
      return updateQuestion();
    }
  }

private Pagereference saveNewQuestion(){ 
    Survey_Question__c newQuestion = new Survey_Question__c();
    newQuestion.Survey__c = surveyRef;
    newQuestion.Name = questionToName(qQuestion);
    newQuestion.Choices__c = qChoices;
    newQuestion.Weights__c = qWeights;
    newQuestion.Required__c = qRequired;
    newQuestion.Type__c = questionType;
    newQuestion.OrderNumber__c = getNewQuestionNum();
    newQuestion.Question__c = qQuestion;
    resetViewsToFalse(true);
    try{
      insert newQuestion;
    }catch(Exception e){
      System.debug(e);
    }
    return saveOrUpdateReturn();
  }

 private Pagereference updateQuestion(){
    //questionToUpdate is setup in an earlier call to editQuestion()
    questionToUpdate.Name = questionToName(qQuestion);
    questionToUpdate.Choices__c = qChoices;
    questionToUpdate.Weights__c = qWeights;
    questionToUpdate.Required__c = qRequired;
    questionToUpdate.Type__c = questionType;
    questionToUpdate.Question__c = qQuestion;
    try{
      update questionToUpdate;
      resetViewsToFalse(true);
      deleteOldResponses(questionToUpdate.id);
      questionReference = null;
    }catch(Exception e){
      System.debug(e);
      Apexpages.addMessages(e);
    }
    
    return saveOrUpdateReturn();
  }

  private Pagereference saveOrUpdateReturn(){
    setupQuestionList();
    Pagereference pr = new Pagereference('/apex/SurveyPage?id='+surveyRef);
    questionType = '--SELECT--';
    if(saveAndNew != null  && saveAndNew == true){
      saveAndNew = False;
      showSelectQuestionType = 'True';      
      return pr;
    }
    else{  
      showSelectQuestionType = 'False';      
      return pr; 
    }
  }