You need to sign in to do that
Don't have an account?
Simon234
"Break" doesn't work for "for"
I can't break this loop:
List<User> userList = [SELECT Id FROM User WHERE UserRole.Name = 'X']; for(Obj__c obj: Trigger.new){ for(User user : userList){ if(obj.CreatedById != user.Id){ obj.OwnerId = user.Id; } } }I need to reassign an object if user's Role != 'X'.
[If there are more than one user in your org with same role, SOQL query will return multiple user records and loop will give inconsistent result]
You can also do away with inner loop if you only have one user in List.
Please mark this as Best Answer, if this helps solve your problem
Use below code:
Hope this will help you. Let me know if it helped or you need any more assistance.
Please mark this is as the solution if it solved your purpose.
Thanks,
Sohan Raj Gupta