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
Deepika Gupta 26Deepika Gupta 26 

Get user name by SOQL

Could any one suggest that how can i get current user name and comare it with one the field of the account which has a lookup with user after trgger insert/update.
saikat sarkarsaikat sarkar
Try UserInfo.getUsername() or UserInfo.getUserId()
Select Id, Name From User Where Id =:UserInfo.getUserId()
Amit Chaudhary 8Amit Chaudhary 8
If you want to get the logged in user detail then please check below method to see all userInfo
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_userinfo.htm

Please try below method
UserInfo.getUsername()

User-added image


other wise you can try below SOQL
 
List<User> lstUser =[select id,userName from user ];
Add where condition if required

Let us know if this will help you

Thanks
Amit Chaudhary