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 ...
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 ...
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 ...
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>&...
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.
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, ...
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 ...
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:
...
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 ...
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 ...
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 ...
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 ...
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
...
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 ...
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="{!...
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 ...
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 ...
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 ...
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 ...
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 ...
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(...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
user × 624apex × 132
profile × 67
soql × 49
community × 46
user-management × 39
permissions × 36
trigger × 34
visualforce × 33
email × 28
unit-test × 20
user-record × 20
customer-community × 19
permission-sets × 19
licenses × 18
rest-api × 16
query × 15
administration × 15
customer-portal × 15
userlicense × 15
api × 14
visual-workflow × 14
email-template × 14
contact × 14
chatter × 13