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
phani kumar 40phani kumar 40 

write trigger on picklist values

when ever parent picklist chages automatically child picklist values should be chage
ex: my parent picklist 1,2,3,4
     child picklist values 1a,1b,2a,2b....like that
   
Shrikant BagalShrikant Bagal
Hello Phani,

You can use Dependent field feature of Salesforce.com 

Please refer following link for How you can create a dependent Field in Salesforce/

https://developer.salesforce.com/docs/atlas.en-us.fundamentals.meta/fundamentals/adg_simple_app_adv_field_dependencies_try_it_out.htm

Hope its help you!!
Jigar.LakhaniJigar.Lakhani
Hello,

Below is sample trigger for your requirement.
Consider Account as your parent object with ParentPicklist__c field and its contact as child objecct with ChildPicklist__c field.

Apex Trigger
trigger AcccountTrigger on Account(AFTER UPDATE){
	
	// After Update Trigger
	if (Trigger.IsAfter && Trigger.IsUpdate) {
		
		Set<Id> setAccountId = new Set<Id>();
		for (Account objAccount.trigger.New) {
			if (objAccount.ParentPicklist__c != Trigger.OldMap.get(objAccount.Id).ParentPicklist__c) {
				setAccountId.Add(objAccount.Id);
			}
		}
		
		List<Account> listAccountWithContacts = new List<Account>([SELECT Id,Name,ParentPicklist__c,(SELECT Id,Name,ChildPicklist__c FROM Contacts) WHERE Id In:setAccountId]);
		List<Contact> listUpdateContacts = new List<Contact>();
		for (Account objAccount:listAccountWithContacts) {
			for (Contact objContact:objAccount.Contacts) {
				if (objAccount.ParentPicklist__c == '1') {
					objContact.ChildPicklist__c = '1A';
				} else if (objAccount.ParentPicklist__c == '2') {
					objContact.ChildPicklist__c = '2B';
				} else if (objAccount.ParentPicklist__c == '3') {
					objContact.ChildPicklist__c = '3C';
				}
				listUpdateContacts.Add(objContact);
			}
		}
		if (listUpdateContacts != null && listUpdateContacts.size() > 0) {
			Update listUpdateContacts;
		}
	}
	
}

Thanks & Cheers,
Jigar(pateljb90@gmail.com)