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
Akshay MhetreAkshay Mhetre 

Picklist to Text - Auto populate

Hello Everyone...

I have one picklist  Hunter_Final_Status__c  having Pending,Clear,Decline,Suspect values.

Condition:: Once any of (Hunter_Final_Status__c) above value is selected, that value should populate/Display in Hunter_Status__c (Text).

 

Best Answer chosen by Akshay Mhetre
Suraj Tripathi 47Suraj Tripathi 47
Hi,

Please follow the below code:-
Make a trigger on object that have the required fields:-
trigger objtrigger on object1 (after update, after insert){

List<object1> objList = trigger.new;
for(object1  o: objList){
   if(o.hunter_final_statuc__c != null){
    o.hunter_status__c = o.hunter_final_statuc__c;
}
}
   update objList;
}

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi

 

All Answers

VinayVinay (Salesforce Developers) 
Hi Akshay,

You can try using workflow field update or process builder to acheive above functionality.

Thanks,
Akshay MhetreAkshay Mhetre
I need code. can you help me.
Suraj Tripathi 47Suraj Tripathi 47
Hi,

Please follow the below code:-
Make a trigger on object that have the required fields:-
trigger objtrigger on object1 (after update, after insert){

List<object1> objList = trigger.new;
for(object1  o: objList){
   if(o.hunter_final_statuc__c != null){
    o.hunter_status__c = o.hunter_final_statuc__c;
}
}
   update objList;
}

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi

 
This was selected as the best answer
Akshay MhetreAkshay Mhetre
Hey Suraj...thanks a lot...same logic i was building... 
Akshay MhetreAkshay Mhetre

Hey Suraj

Few changes in requirments:: if I choose Hunter_Final_Status__c  as "Clear" ,Hunter_Status__c (Field on Opportunity)(text field)  should also change to "Clear" 

trigger HunterStatusUpdate on Case (after update, after insert) {
List<case> caseList = trigger.new;
for(case  caseRecord: caseList){
   if(caseRecord.Hunter_Final_Status__c == Clear ){
    Opportunity.Hunter_Status__c  = caseRecord.Hunter_Final_Status__c;
}
}
   update caseList;  
}

facing errors:: 
A value cannot be stored to Hunter_Status__c in type Opportunity
Variable does not exist: Clear
Doubt:: while writing caseRecord.(Fields were not auto populating here) ...why?? same while Opportunity.(Fields were not auto populating here).

Suraj Tripathi 47Suraj Tripathi 47
Hi,
Please change Clear to this-  'Clear'.