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
Benjamin BolopueBenjamin Bolopue 

Trigger to Update Lookup Field based on Picklist Selection

Hello All,
Understanding full well that back in February, a similar question was posted by DannyTK, (!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000AyhxIAC" target="_blank) My scenario is slightly different, and I'm no developer. Any insight the community has to offer would be greatly appreciated! Here are the details:

1.) I'm working on a project that requires my Users be able to update a Lookup field (Owner__c) via a picklist selection.
2.) I have a simple formula field (Re_Assigned_To_ID__c) that produces a User ID based on the selection made via item 1's picklist.
3.) Owner__c and Re-Assigned_To_ID__c are custom fields on a custom object named NPS_Survey__c
4.) I think (please correct me if I'm wrong!) I need a trigger that fires when Re_Assigned_To_ID__c is changed and uses Re_Assigned_To_ID__c's value ( a User's ID) to update the Owner__c (Lookup field) value. 

Thanks for your time!

Hi Ben,

You can try this code:
trigger OwnerUpdate on NPS_Survey__c( before insert, before update )
	for( NPS_Survey__c sur : )
		if( (trigger.isInsert
			|| ( trigger.isUpdate && trigger.oldMap.get( sur.Id).Assigned_To_ID__c != sur.Assigned_To_ID__c ))
			&& sur.Assigned_To_ID__c != null )
			sur.Owner__c = sur.Assigned_To_ID__c;

Any luck Ben, or you still having the issue.