Hot answers tagged

30 votes
Accepted

SOQL to find All Users with a Custom Permission

Update Please note that for the running user, you can use the FeatureManagement class: Boolean isEnabled = FeatureManagement.checkPermission('My_Permission_Api_Name'); Surprisingly, I don't think ...
Adrian Larson's user avatar
  • 149k
24 votes

Automated Process User Profile Permissions

I've found Matt's answer on the IdeaExchange You can follow the recommendation from Roy Lloyd and create a Permission Set and assign the autoproc User in Exec-Anonymous: insert new ...
Steven.B's user avatar
  • 470
19 votes
Accepted

Is Username Globally Unique?

Salesforce is split across login "domains." Each domain uses its own username index, which means it's entirely possible to create the exact same user on login.salesforce.com, test.salesforce.com, and ...
sfdcfox's user avatar
  • 481k
14 votes
Accepted

Find users under a node in role hierarchy

I would get the UserRole records you want first and then query the User records. Grouping UserRole Records by Parent // public with sharing class RoleHierarchy static Map<Id, List<UserRole>&...
Adrian Larson's user avatar
  • 149k
13 votes
Accepted

Deleting Users from Salesforce permanently

As of today, there's still no way to do that. You can, however vote on this idea, that's currently on review.
Fernando Gavinho's user avatar
10 votes
Accepted

How do I reset an API user's password?

To some degree it will depend on the security requirements for your organization. If you absolutely must change the password, then you can use the current session to call SetPassword(). Of course, ...
Daniel Ballinger's user avatar
10 votes

How can you access display languages via Apex?

Based on the documentation of the User object, if you remove a language from the Displayed Languages, the corresponding PicklistEntry becomes inactive. Based on my experimentation, this appears to ...
Adrian Larson's user avatar
  • 149k
8 votes

APEX test user creation

Building on this answer, I construct my test classes @TestSetup methods such that I can create an arbitrary number of unique users using a shortened 8-char GUID to init the names and emails, like so: ...
Shanerk's user avatar
  • 1,042
8 votes
Accepted

Formula Specific to Running User?

There are a few approaches you can take here, which I will list in order of preference. These should work just about anywhere merge fields can be used. Create a Custom Permission You can check if ...
Adrian Larson's user avatar
  • 149k
8 votes

Mixed DML operation error

You must specify UserRoleId as null. Reference: You can insert a user in a transaction with other sObjects in Apex code saved using Salesforce API version 15.0 and later if UserRoleId is specified ...
Adrian Larson's user avatar
  • 149k
8 votes
Accepted

Permissions & Settings in Profile and Permission Set and its Usage

The Rule of thumb is permission set extend the access of profile and do not restrict. 1.In first scenario since profile already has access which means permission set cannot disable as permission sets ...
Mohith Shrivastava's user avatar
8 votes
Accepted

How can I delete a contact which was associated with a customer portal user?

Just to add to @John Thompson's answer, you can add the button that disables the customer user: This will remove the connection between the user and the contact, and mark the user as deleted. If you ...
Itai Shmida's user avatar
  • 4,995
8 votes

It is possible to clone a user in salesforce from exsting user?

It is possible. Please take a look at below link https://success.salesforce.com/answers?id=90630000000grMNAAY I did try this on my end by creating a custom link on User Object & it worked smooth ...
night crawler's user avatar
8 votes

In test class can see all org users in list

This is the expected behavior and is documented in the Isolation of Test Data from Organization Data in Unit Tests (emphasis mine): Starting with Apex code saved using Salesforce API version 24.0 ...
Jayant Das's user avatar
  • 30.3k
7 votes
Accepted

Retrieving the profile photo for a user

Use user's FullPhotoUrl and SmallPhotoUrl fields VF code: <apex:page controller="cls_PhotoUrl"> <apex:form> <apex:image value="{!...
Ratan Paul's user avatar
  • 22.5k
6 votes
Accepted

Customer Community Plus User Cannot Add Other User

Explanation Take a look at sObjects That Cannot Be Used Together in DML Operations. It is not your call to UserInfo.getUserRoleId() that is causing the error. You get the error because you are setting ...
Adrian Larson's user avatar
  • 149k
6 votes

Query all the queue a user belong

The Sobject you should query is GroupMember. But it have the membership details of both Queue and Public Group. So you need to differentiate it using the Group type as 'Queue'. Select Group.Name from ...
Vigneshwaran G's user avatar
6 votes
Accepted

License Limit Exceeded Error while creating user

There is no solution to this since you have consumed all the license that were allocated for your org . Deactivate the existing users if you are testing your code . You can also purchase additional ...
Mohith Shrivastava's user avatar
6 votes
Accepted

JSON.deserialize() for User records wont work

I was able to reproduce the issue in my DEV org by creating a class named User. Another class has following code: User user = (User) JSON.deserialize('{}', User.class); Which yeilds the same error ...
Raul's user avatar
  • 18.7k
6 votes
Accepted

SOQL returning incorrect value

This is a Known Issue that can occur. It goes way back to the days when the standard profiles were named PTX, where X was a number. They still occasionally end up showing up in odd places, and you've ...
sfdcfox's user avatar
  • 481k
6 votes
Accepted

Is there a to check how many users using compact/comfy display density view?

You can query against the UserPreference object. Looking at the doc, you can see that density is stored as 108 in the Preference field and has been included since API 44. You can include tolabel(...
Kris Goncalves's user avatar
5 votes
Accepted

Get User Language in Visualforce without controller

Looks like language field is not available via $User global variable. Here is a knowledge article about it https://help.salesforce.com/apex/HTViewSolution?id=000205451&language=en_US I checked ...
Salesforcesmarty's user avatar
5 votes

Freeze User through code and make report on them

Here is some sample code that I used to this: List<UserLogin> users = [SELECT IsFrozen,UserId FROM UserLogin WHERE UserId IN (SELECT Id FROM User WHERE Profile.Name != 'System ...
Force2b_Mike's user avatar
5 votes

How to query users who have access to a particular record?

You can use userRecordAccess object to check CRUD permissions.. So pass the recordId and userId.. to check that user having what type of access on that record.. you can check variables like ...
Ratan Paul's user avatar
  • 22.5k
5 votes
Accepted

What is a 'CSS User'?

The Customer Self-Service ("CSS") user is used by the classic Self-Service Portal. It represents the customer who has logged in and is doing something with the case (e.g. logging the case, adding a ...
sfdcfox's user avatar
  • 481k
5 votes

Test coverage for a user trigger: How to prevent "DML not allowed on User" in test-class?

I don't know why, but all you need is to change upsert u; into insert u; update u; and all the pain goes away. You can save without any problem and the coverage is there. I found this ...
Uwe Heim's user avatar
  • 28.3k
5 votes
Accepted

Can I assign Permission set to a profile instead of user?

We can not able to assign Permission set to Profile. We need to assign it to a User only. A permission set is a collection of settings and permissions that give users access to various tools and ...
Devendra's user avatar
  • 5,067
5 votes

Can I assign Permission set to a profile instead of user?

AFAIK the platform has no direct support for this. But you can write workflow logic or trigger code to add/delete the PermissionSetAssignment objects automatically based on attributes of the User ...
Keith C's user avatar
  • 135k
5 votes
Accepted

User Licenses Remaining?

We have a UserLicense object in Salesforce, which stores all the license count information. Link to documentation: UserLicense object. Query: select Id, Name, UsedLicenses, TotalLicenses, Status, ...
Ysr Shk's user avatar
  • 3,104

Only top scored, non community-wiki answers of a minimum length are eligible