You need to sign in to do that
Don't have an account?
Cody Drennon 7
How to retrieve the value of a picklist that was selected by a user, using a trigger
Below i am trying to replace User.Name with the name of my picklist field(Change_Owner__c) and then Cody Dren with whatever the user selected from the picklist(Cody D, Kyle W, Jen J etc). Can someone please help me with this.
Thanks.
Trigger UpdateOwnerID on Case (before insert, before update) {
User objUser = [select Id from User where User.Name = 'Cody Drennon' limit 1];
for (Case objCase : Trigger.new)
{
if (objCase.OwnerId <> objUser.Id)
{
objCase.OwnerId = objUser.Id;
}
}
}
Thanks.
Trigger UpdateOwnerID on Case (before insert, before update) {
User objUser = [select Id from User where User.Name = 'Cody Drennon' limit 1];
for (Case objCase : Trigger.new)
{
if (objCase.OwnerId <> objUser.Id)
{
objCase.OwnerId = objUser.Id;
}
}
}
What you're trying to do is take a field value from your in scope Case (objCase) and find a User. To do that, you have to have something on the user record that will match the value from the Change_Owner__c field. If you were to add a field on the user record called Case_Owner_Code__c (again, it doesn't matter what you call it), something like this should work:
All Answers
Trigger UpdateOwnerID on Case (before insert, before update) {
User objUser = [select Id from User where User.Name = Case.Hidden_Owner_Change__c limit 1];
for (Case objCase : Trigger.new)
{
if (objCase.OwnerId <> objUser.Id)
{
objCase.OwnerId = objUser.Id;
}
}
}
What you're trying to do is take a field value from your in scope Case (objCase) and find a User. To do that, you have to have something on the user record that will match the value from the Change_Owner__c field. If you were to add a field on the user record called Case_Owner_Code__c (again, it doesn't matter what you call it), something like this should work: