1

Getting profile and their custom objects having read access based on the userLicense type

using below method I am fetching the list of profile and corresponding object's count having READ access and displaying them into lightning component.

     @AuraEnabled
 public static List<AggregateResult> getProfileInfo() {
    Set<String> sobjectNames = new Set<String>();
    for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() ){
       Schema.DescribeSObjectResult objResult = o.getDescribe(); 
           if(
               !objResult.getName().startsWith('Flosum') && !objResult.getName().startsWith('pi__') &&
               !objResult.getName().startsWith('DMAPP__') && !objResult.getName().startsWith('DMMAX__') &&
               !objResult.getName().startsWith('DMPPT__') && !objResult.getName().startsWith('DMSPM__') &&
               !objResult.getName().startsWith('APXTConga4__') && !objResult.getName().startsWith('LEXMAGICMOVER__') &&
               !objResult.getName().startsWith('CRMC_PP__')
             ){
                sobjectNames.add(objResult.getName());
              }
           }     
   List<AggregateResult> plist = new List<AggregateResult>();
   plist = [SELECT Parent.Profile.Name Name, COUNT(SObjectType) Quantity FROM ObjectPermissions 
            WHERE (ParentId IN (SELECT PermissionSetId FROM PermissionSetAssignment)) 
            AND Parent.IsOwnedByProfile = true 
            AND PermissionsRead = true
            AND PermissionsCreate = false
            AND PermissionsDelete = false
            AND PermissionsEdit = false
            AND PermissionsModifyAllRecords = false
            AND PermissionsViewAllRecords = false
            AND (SObjectType IN :sobjectNames) 
            GROUP BY Parent.Profile.Name];
   return plist;
 }

Above code is working fine now I want to fetch profiles and corresponding custom objects based on the userLicense selected from dropdown from the component. So I am passing the name like 'Salesforce' from component to this method, so how can I pass the selected license type in this where clause ? Because I couldn't found any relation between "ObjectPermission" and "UserLicense" objects.

Here is the query which can fetch profile based on the licenses.

Map<Id,Profile> profileIds = new Map<id,profile>([SELECT Id, Name, UserLicenseId FROM Profile where UserLicenseId  in (SELECT Id FROM UserLicense where name ='Salesforce')]);
  • you have tagged this question as lightning-components but it is not related to that, I have added tags for you, this way more relevant people would see your question – Itai Shmida Sep 3 '18 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.