+ Start a Discussion
VRKVRK 

formula field help for fetch picklist values dynamically

Hi ..
HI i am created one formula field which fetch value of StageName( picklist ) value.
if picklist value select As 01 - Funded, the formula field updated As 01.
if picklist value select As 02 - Approved, the formula field updated As 02.
Below coding is working fine, But i need write Dynmic instead of pass static Values.
We have 100 picklist values, So is there any way to write logic as dynamic ..

IF(ISPICKVAL( StageName , "01 - Funded"), "01",
IF(ISPICKVAL( StageName , "02 - Approved"), "02",
IF(ISPICKVAL( StageName , "03 - Underwriting - In Process"), "03",
IF(ISPICKVAL( StageName , "04 - Term Sheet Issued/Pre-Underwriting"), "04", ""))))

Thanks
VRK
Best Answer chosen by VRK
ANUTEJANUTEJ (Salesforce Developers) 
I tried a formula field on account object of text type to fetch the first 3 characters of the type of account and this below formula worked for me
LEFT( TEXT(Type) , 3)

You can change it to something like below
LEFT( TEXT(StageName) , 2) 

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi VRK,

>> https://developer.salesforce.com/forums/?id=9060G000000I1b2QAC

I was able to find the above link that has an implementation that is a formula field that trims the first 3 letters. Please check the above link and modify as necessary.

For quick reference I am adding the best answer below so that it is easily accessible.
 
'[' + IF(FIND(' ',TRIM(test_text__c ))==0|| FIND(' ',TRIM(test_text__c),FIND(' ',TRIM(test_text__c),1)+1)==0,
 TRIM(test_text__c ),
 TRIM(LEFT(TRIM(test_text__c)+' ', FIND(' ',TRIM(test_text__c )+' ',
                         FIND(' ',TRIM(test_text__c )+' ',  
                         FIND(' ',TRIM(test_text__c )+' ',1)+1)+1)))) + ']'

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
ANUTEJANUTEJ (Salesforce Developers) 
I tried a formula field on account object of text type to fetch the first 3 characters of the type of account and this below formula worked for me
LEFT( TEXT(Type) , 3)

You can change it to something like below
LEFT( TEXT(StageName) , 2) 

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
This was selected as the best answer
VRKVRK
Thank  you AnuTej, its working correctly