You need to sign in to do that
Don't have an account?
himanshu huske 7
change owner of record
please correct my code below,
I have one object Customer__c,In this there are one picklist User_to_b__c.
if valid userName is input in User_to_b__c field. owner field should update with value in User_to_b__c
I have one object Customer__c,In this there are one picklist User_to_b__c.
if valid userName is input in User_to_b__c field. owner field should update with value in User_to_b__c
trigger Cust_User_to_be on Customer__c (before insert, before update) { Set<string> strSet = new Set<String>(); for(Customer__c cs : trigger.new) { strSet.add(cs.User_to_b__c); } map<string,id> csMap = new map<string,id>(); for(User u : [Select id,Name from user where Name IN :strSet]) { csMap.put(u.Name,u.Id); } for (Customer__c cs : Trigger.new) { if (cs.OwnerId <> csMap.get(cs.User_to_b__c) ) { cs.OwnerId = csMap.get(cs.User_to_b__c); } } }
Can you please try above code, mark it best if it solves your problem.