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
TilluTillu 

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){
cset.add(c.id);
}

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;
System.Debug('User>>>>'+U.id);
System.Debug('NameUser>>>>'+Cs.UserName__c);
}
}
}
}
Mark TroupeMark Troupe
Your UserList query is returing ALL users, not just the user editing the record.

use 
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