You need to sign in to do that
Don't have an account?
Rick SF Admin
Trigger to auto populate a date field when a picklist value is selected
I am trying to create a trigger that will auto populate a date field when a picklist value is selected. I'm trying to achieve this without creating another custom object.
Ex. PIcklist Values: Test, Demo, Draft
If Test; then date value = 12/1/2018
If Demo, then date value = 11/1/2018
If Draft then, date value = 10/1/2018
Ex. PIcklist Values: Test, Demo, Draft
If Test; then date value = 12/1/2018
If Demo, then date value = 11/1/2018
If Draft then, date value = 10/1/2018
You can simply use a Formula field with return type date in order to populate your date field. The formula would look something like:
CASE(TEXT(PicklistField__c), 'Test', DATE(2018,12,1), 'Demo', DATE(2018,11,1), 'Draft', DATE(2018,10,1), null)
In a similar manner, you can go on and add your 20 different picklist values in value/result pair. Please NOTE that the last value is the value that will be populated in case none of the conditions meet the criteria.
Hope this helps.
All Answers
You can simply use a Formula field with return type date in order to populate your date field. The formula would look something like:
CASE(TEXT(PicklistField__c), 'Test', DATE(2018,12,1), 'Demo', DATE(2018,11,1), 'Draft', DATE(2018,10,1), null)
In a similar manner, you can go on and add your 20 different picklist values in value/result pair. Please NOTE that the last value is the value that will be populated in case none of the conditions meet the criteria.
Hope this helps.