You need to sign in to do that
Don't have an account?
Gireesh A 7
HI Basically i am changing the owner ship from one user to other user using trigger,i am getting error Error: Compile Error: Method does not exist or incorrect signature: void contains(Id) from the type User at line 21 column 11
trigger UpdateOwnerID on Case (after insert) {
List<Case> cases = new List<Case>();
map<Id,String> userIdbyAlias = new map<Id,String>(); //Keep in mind this will only store one user id per alias
for(User u : [Select id,Name from user where IsActive = true AND Profile.Name = 'AH JP – Customer Request Agent'])
{
userIdbyAlias.put(u.Id,u.Name);
system.debug('*** User names'+userIdbyAlias);
}
system.debug('**List of user from profile **'+userIdbyAlias);
for (Case c : [Select Id, OwnerId, CreatedById From Case Where Id IN : Trigger.newMap.keySet()]) {
for(User u :userIdbyAlias.keySet()){
if(u.contains(c.OwnerId)) {
c.OwnerId = userIdByAlias.get(u).Id;
cases.add(c);
}
}
}
if(cases.size() > 0)
update cases;
system.debug('*** Final Output ***'+cases);
}
List<Case> cases = new List<Case>();
map<Id,String> userIdbyAlias = new map<Id,String>(); //Keep in mind this will only store one user id per alias
for(User u : [Select id,Name from user where IsActive = true AND Profile.Name = 'AH JP – Customer Request Agent'])
{
userIdbyAlias.put(u.Id,u.Name);
system.debug('*** User names'+userIdbyAlias);
}
system.debug('**List of user from profile **'+userIdbyAlias);
for (Case c : [Select Id, OwnerId, CreatedById From Case Where Id IN : Trigger.newMap.keySet()]) {
for(User u :userIdbyAlias.keySet()){
if(u.contains(c.OwnerId)) {
c.OwnerId = userIdByAlias.get(u).Id;
cases.add(c);
}
}
}
if(cases.size() > 0)
update cases;
system.debug('*** Final Output ***'+cases);
}
Does this work? Let me know.
--
Abhi
i have tried before as you suggested but stil same error i am getting
Error: Compile Error: Method does not exist or incorrect signature: void contains(Id) from the type Map<Id,String> at line 19 column 23
Again you are assigning same user id in the trigger.I think case owner id not contained in the map you need assign map key.
please check once below code :
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Please use below code. Either lne 13 or 14 will work. Please let me know if you need any help. Mark as best answer if helped.
Regrads,
Ramakant
Finally i have ended up with below trigger ,can you please tell me how do i get the new user from map ,please finnd the below my comment where i getting error
trigger UpdateOwnerID on Case (before insert,before update) {
map<Id,User> userIdbyAlias = new map<Id,User>(); // this will only store one user id per alias
for(User u : [Select id,Name from user where IsActive = true AND Profile.Name = 'AH JP – Customer Request Agent'])
{
userIdbyAlias.put(u.Id,u);
system.debug('*** User names'+userIdbyAlias);
}
system.debug('**List of user from profile **'+userIdbyAlias);
for (Case c : [Select Id, OwnerId, CreatedById From Case
Where Id IN : Trigger.new]) {
if(userIdByAlias.containskey(c.OwnerId)) {
if (c.OwnerId <> userIdByAlias.get(u).Id )
c.OwnerId = userIdByAlias.get(u).Id; // getting error here
Error: Compile Error: Variable does not exist: u at line 16 column 44
system.debug('*** Chnaged user **'+c.OwnerId);
system.debug('*** Assigning user ***'+userIdByAlias.get(u).Id);
}
}
}
I don't know why the name of your map says alias but you are not storing any alias in it. However, please try the below code.
You were trying to access 'u' out of its scope, hence you got the error.
--
Abhi
Can you confirm one thing here ,i have implememnted sharing rule ,does it impact for the above role of profile users ,does it impact still we wright a trigger?
I am not going deeper into the business requirement. I hope you are well aware of it and know what you are doing with this trigger.
--
Abhi
You will have to query the users in that role, assign when the user ids dont match (between the queried users from the role vs the case owner user).
As you suggested i have tried with querry the user list based on role.look at the first for loop in the trigger
trigger UpdateOwnerID on Case (before insert,before update) {
map<Id,User> userIdbyAlias = new map<Id,User>(); // this will only store one user id per alias
for(User u : [Select id,Name,UserRole.Name from user where IsActive = true AND Profile.Name = 'AH JP – Customer Request Agent' AND UserRole.Name ='AH JP– Tech Advisor'])
{
userIdbyAlias.put(u.Id,u);
system.debug('*** User names'+userIdbyAlias);
}
system.debug('**List of user from profile **'+userIdbyAlias);
for (Case c : [Select Id, OwnerId, CreatedById From Case
Where Id IN : Trigger.new]) {
if(userIdByAlias.containskey(c.OwnerId)) {
if (c.OwnerId <> userIdByAlias.get(c.OwnerId).Id )
c.OwnerId = userIdByAlias.get(c.OwnerId).Id; // getting error here
system.debug('*** Changed user **'+c.OwnerId);
system.debug('*** Assigning user ***'+userIdByAlias.get(c.OwnerId).Id);
}
}
}