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
Kumar Rao 1Kumar Rao 1 

Validation Rule = Set Dependent Picklist Value based on another Picklist Value

Dear Folks,

Can someone please help to frame the syntax?

I have 2 Picklists
Pick list 1 (values: Quarterly, Annually)
Pick list 2 (values: Quarterly, Annually)

If Pick list 1 value is Quarterly then Set Pick list 2 value to Quarterly
If Pick list 1 value is Annually then Set Pick list 2 value to Annually

Thanks,
Kumar
 
Abhishek BansalAbhishek Bansal
Hi,

In order to acheive this, Please create a trigger on your Object where these two picklist fields exist with the below code :
trigger changeValue on CustomObject__c(before insert, before update){
	for(CustomObject__c obj : trigger.new){
		if(trigger.isInsert || (trigger.isUpdate && trigger.oldMap.get(obj.id).picklist1__c != obj.picklist1__c)){
			obj.picklist2__c = picklist1__c;
		}
	}
}
//Please replace the following variables with the API name :
//1. CustomObject__c - API name of custom object on which these two picklist exists.
//2. picklist1__c - Api name of Fisrt Picklist field whose value you want to copy.
//3. picklist2__c = API name of second picklist field in which you want to copy values.

Let me know if you need any help or if you have any issue.

Thanks,
Abhishek
☯ BonY ☯☯ BonY ☯
Hi kumar,

you have to set field depedencies.

User-added image

goto -> field dependecies -> new.

set Controlling filed as picklist 1 and Dependent Field as picklist 2.

include picklist2 value. 
User-added image

let me know, if u need any hlp.

thanks,
♔BoNi