3

I'm trying to get selected values and labels of picklist (Multi-Select) for a record of custom object and store these values in list of string but size of it not displayed.

Apex Class

public with sharing class customCtrl {
    private ApexPages.standardController stdController;

    Id recordId = 'a0Z25000001Vq02';
    public String[] tmpString { set {
        customObj__c a = [SELECT list_tasks__c
                          FROM customObj__c
                          WHERE Id =: recordId limit 1];
        this.tmpString = a.list_tasks__c.split(';');
    } get;}


    public customCtrl(ApexPages.StandardController controller) {
            this.stdController = stdController;
    }
}

VisualForce Page

<apex:page standardController="customObj__c" extensions="customCtrl" >
  <!-- Begin Default Content REMOVE THIS -->
  <apex:form >
  <apex:pageBlock title="List of Selected">
      <apex:pageBlockSection >
          list length is {!tmpString.size}

      </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
  <!-- End Default Content REMOVE THIS -->
</apex:page>
  • I tried this and it is the same, return nothing @Ratan – user3003810 Jan 26 '16 at 13:58
  • list_tasks__c field having values? – Ratan Paul Jan 26 '16 at 14:00
  • You should define default constructor in the class as public customCtrl() {} then try. – Peeyush Jan 26 '16 at 14:02
  • of course, list of values and I created record and I select values from this list (2 of 8) .. and the record id is a0Z25000001Vq02 – user3003810 Jan 26 '16 at 14:03
  • I already do that ` public customCtrl(ApexPages.StandardController controller) { this.stdController = stdController;}` @PeeyushSachdeva – user3003810 Jan 26 '16 at 14:06
0

Change your controller code and add code into constructor

public with sharing class customCtrl {


    private ApexPages.standardController stdController;

    public List<String> tmpString {get; private set}

    public customCtrl(ApexPages.StandardController controller) {
            this.stdController = stdController;
            Id recordId = 'a0Z25000001Vq02';
            tmpString = new List<String>();
            customObj__c a = [SELECT list_tasks__c
                          FROM customObj__c
                          WHERE Id =: recordId limit 1];
            tmpString.addAll(a.list_tasks__c.split(';'));

    }
}
| improve this answer | |
  • Humm, it works for me thank you. but what is the point ?? what if I want to get these values for each selected record from table for example. – user3003810 Jan 26 '16 at 14:49
  • @user3003810 what do you mean I didn't get you – Ratan Paul Jan 26 '16 at 14:54
  • I mean this code will be triggered on first page load, what If I'd a table of records and when I click on any row I'll get selected list of tasks for that record? as a method getSelected(Id) – user3003810 Jan 26 '16 at 14:58
  • @user3003810 you may need to pass you row record id in controller and based id need to query to get list – Ratan Paul Jan 26 '16 at 15:01

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.