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
Project2Project2 

How do i assign a picklist value to string

Hi, need help with assigning a picklist value to a string. Something like this

 

Reference_Key2__c = TEXT(Dispute_New__c.Status__c)

 

where 'status__c' is a pick list and Reference_Key2__c is a string.

Best Answer chosen by Admin (Salesforce Developers) 
kevoharakevohara

All you need to do is assign it to a String variable.  It's stored as a String.

 

Reference_Key2__c = Dispute_New__c.Status__c;

All Answers

kevoharakevohara

All you need to do is assign it to a String variable.  It's stored as a String.

 

Reference_Key2__c = Dispute_New__c.Status__c;

This was selected as the best answer
pbattissonpbattisson

Hey,

 

Are you trying to do this in a formula field or in apex code?

 

If it is a formula field then the formula you want is TEXT(Dispute_New__c.Status__c). 

 

If it is in apex code, then retrieveing the alue from a single select picklist should return as a string.

 

Paul

Project2Project2

This is in apex

elpaso750elpaso750

Hi, thanks to the thread.

 

the simple assignment in apex did not work.

 

any solved like this :

 

I have this is the constructor :

 

 

// constructor
    private final Software_Testing__c o;
    public TestSearchController(ApexPages.StandardController stdController) {
         this.o = (Software_Testing__c)stdController.getRecord();
// constructor    private final Software_Testing__c o;    public TestSearchController(ApexPages.StandardController stdController) {         this.o = (Software_Testing__c)stdController.getRecord();

 

 

and this for the assingment :

 

        searchText = o.Platform__c; // allocate the correct value
        String qry = 'Select c.Name, c.Average_Time_Spent__c, c.Platform__c, c.Description__c, c.Id From Testing_Item__c c Where c.Platform__c INCLUDES (: searchText) Order By c.Name';

 

 

 

 

 

Also added this to provide a default value :

 

 

    public string searchText {
        get {
            if (searchText == null) searchText = 'CMF'; // prefill the search box for ease of use
            return searchText;
        }
        set;
    }