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
Stavros McGillicuddyStavros McGillicuddy 

Copy a picklist value to a text field need syntax

I am trying to copy a picklist value to a text field with a custom button but can't figure out the syntax.

This syntax populates the field with
TEXT(!Opportunity.AVSFQB__Generate_Object__c) 
 
record.Sample_Generate__c = 'TEXT(!Opportunity.AVSFQB__Generate_Object__c)'; 

Thank you
Best Answer chosen by Stavros McGillicuddy
Nayana KNayana K
I think this will work.
record.Sample_Generate__c = '{!Opportunity.AVSFQB__Generate_Object__c}'; 

All Answers

Nayana KNayana K
I think this will work.
record.Sample_Generate__c = '{!Opportunity.AVSFQB__Generate_Object__c}'; 
This was selected as the best answer
SandhyaSandhya (Salesforce Developers) 
Hi Stavros,

I assume you are writing this in formula field.

If so then you  write as below
 
TEXT(Opportunity.AVSFQB__Generate_Object__c);
if in the apex


If it is in Apex code, then retrieving the value from a single select picklist should return as a string.
record.Sample_Generate__c =(!Opportunity.AVSFQB__Generate_Object__c);
For example, the country is picklist and values in the picklist like India; the US are always strings that means (Text) you can directly assign to a string variable.

 
Stavros McGillicuddyStavros McGillicuddy
Thank you for your responses.
This is what worked for me
record.Sample_Generate__c = '{!Opportunity.AVSFQB__Generate_Object__c}';