+ Start a Discussion

How to pass user id for below field ?

For a Case record, if a specified profile user edits the record and save. The user name should populate on  Case field. But whenm i add the condition it was empty. Where it is wrong ?

trigger UpdateCase on Case(before insert,before update) {

set<id> cset = new set<id>();
//Id profileUser = UserInfo.getProfileId();
//profile p = [select id,name from profile where name = 'Operations'];
for(case c:Trigger.new){

List<Case> CaseList = [select id,Assigned_To__c from case where id in:cset];

List<User> UserList = [select id,profile.id,Lastname,name from User];

for(Case Cs:Trigger.new){
for(User u :UserList ){
if(U.Profile.id == '0098467tXEr6767'){
Cs.Assigned_To__c = U.id;
Cs.UserName__c = U.id;
Mark TroupeMark Troupe
Your UserList query is returing ALL users, not just the user editing the record.

List<User> UserList = [select id,profile.id,Lastname,name from User where id =: UserInfo.getUserId limit 1];
This will only return 1 User so you dont need to loop through the list