Saturday, June 20, 2020

Retrieve Permission Set Access using standard Salesforce objects



1. Query to retrieve Object Level Permissions

SELECT Id, ParentId, SobjectType, PermissionsCreate, PermissionsRead
, PermissionsEdit, PermissionsDelete, PermissionsViewAllRecords
, PermissionsModifyAllRecords, CreatedDate, CreatedById, LastModifiedDate
, LastModifiedById, SystemModstamp from objectpermissions
where parent.name = 'PERMISSION_SET_NAME_HERE'

2. Query to retrieve Field Level Permissions

SELECT Id, ParentId, SobjectType, Field, PermissionsEdit, 
PermissionsRead, SystemModstamp from fieldpermissions
where parent.name = 'PERMISSION_SET_NAME_HERE'

3. Query to Retrieve Apex/Visualforce Page/Tab level Access
SELECT Id, ParentId, SetupEntityId, SetupEntityType, SystemModstamp 

FROM SetupEntityAccess

WHERE parent.name = 'PERMISSION_SET_NAME_HERE'

4. Query All system permissions (add all columns from object as needed)

SELECT Id, PermissionsModifyAllData from permissionset 

where name='PERMISSION_SET_NAME_HERE'


Retrieve Profile using Standard Salesforce Objects



Profiles

1. Query to retrieve Object Level Permissions

SELECT Id, ParentId, SobjectType, PermissionsCreate, PermissionsRead
, PermissionsEdit, PermissionsDelete, PermissionsViewAllRecords
, PermissionsModifyAllRecords, CreatedDate, CreatedById, LastModifiedDate
, LastModifiedById, SystemModstamp
FROM ObjectPermissions
WHERE ParentId IN (
  SELECT Id
  FROM PermissionSet
  WHERE Profile.Name  = 'PROFILE_NAME_HERE'
)

2. Query to retrieve Field Level Permissions

SELECT Id, ParentId, SobjectType, Field, PermissionsEdit, 
PermissionsRead, SystemModstamp
FROM FieldPermissions
WHERE ParentId IN ( SELECT Id FROM PermissionSet
WHERE Profile.Name = 'PROFILE_NAME_HERE')

3. Query to Retrieve Apex/Visualforce Page/Tab/App level Access
SELECT Id, ParentId, SetupEntityId, SetupEntityType, SystemModstamp 

FROM SetupEntityAccess

WHERE ParentId IN (

SELECT Id

FROM PermissionSet

WHERE Profile.Name = 'PROFILE_NAME_HERE'

)
4. Retrieve system permissions(Add other system permissions in select clause as needed)

SELECT Id, PermissionsModifyAllData from permissionset 

where id in ( SELECT Id FROM PermissionSet

WHERE Profile.Name = 'Profile Name')




Tuesday, November 19, 2019

Getting Record Type Id in LWC for Particular Record Type Name

import { LightningElement,wiretrack } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class RecordTypeTestLWC extends LightningElement {
    
    @track objectInfo;

    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT ,})
    objectInfo;

    getRecordTypeId(recordTypeName) {
        let recordtypeinfo = this.objectInfo.data.recordTypeInfos;
        let recordTypeId;
        for(var eachRecordtype in  recordtypeinfo)
        {
            if(recordtypeinfo[eachRecordtype].name===recordTypeName){
                recordTypeId = recordtypeinfo[eachRecordtype].recordTypeId;
                break;
            }
        }
        console.log('returning -   ' + recordTypeId);
        return recordTypeId;
    }    


}

Saturday, February 24, 2018

Why does user have access to this field?

How can you find out which permission set or profile gives particular field access ?  Yes there is a way. You can use fieldpermissions object to retrieve this information.

Here is one sample query -

SELECT Id, ParentId, SobjectType, Field, PermissionsEdit, PermissionsRead, SystemModstamp from fieldpermissions where SobjectType = 'Opportunity' and field='stagename' and  parentid in (
SELECT PermissionSetId from permissionsetassignment where assigneeid = '00532000006644')

Here parentid is profile or perm set id.

Monday, April 3, 2017

Retrieve Salesforce Profile XML using Workbench

For retrieving salesforce profile, you need to fetch all metadata components which consists of custom objects, applications, VF pages, Apex classes etc. So in profile retrieve request you not only get profile, but all other metadata components.

In Article Retrieve Metadata Using Workbench, I explained process to use workbench for retrieving a particular metadata type. Profile is also one of the metadata type, but it requires other components with it for it to work.

Here is the sample XML that you can use to retrieve profiles -

https://github.com/sushilgit/ProfileComparison/blob/master/Tool/package.xml

In above xml, if you want to retrieve some specific profiles instead of all, you may update the xml as follows -

 <types>
<members>Custom: Marketing Profile</members>
        <name>Profile</name>
 </types>

What are the type of profile permissions retrieved by above process -

Apex Class
Apex Page
Custom application
Custom Object
Custom Tab
HomePageLayout
Layout
Connected App
External Data Source
Custom Permission

Sunday, April 2, 2017

Salesforce Page Layout Comparison

Are you trying to solve one of the below problems -

1. Want to consolidate two profiles, but they have different page layout assigned. Looking for some automated way to compare big layouts ?

2. Trying to consolidate layouts on object like account and need a way to compare them ? 

I have built a tool to compare layouts which generates side by side comparison in excel with all fields on layout. 

Here is the link to the tool - Layout Comparison Tool

Using Workbench to Retrieve Metadata

This article covers list of steps you can follow to retrieve metadata from salesforce using workbench.

1. First create package.xml file. Here is the sample to retrieve all layouts in the org.

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
 <types>
        <members>*</members>
        <name>Layout</name>
</types>
<version>39.0</version>
</Package>

2. Now go to workbench (Workbench) and login to your sandbox, production or dev org. for Developer org choose Production as environment.



3. After you login, you will see following screen. Click on Migration dropdown and select Retrieve as option. 


4. You will see below screen. Choose package.xml file created in step1 in choose file option. And select single package checkbox. Click Next - 



5. You will see below confirmation screen, Click on Retrieve to start the retrieval process. 



6. Above process runs for some time based on the amount of metadata you have. Once completed, you will see below screen. You can download the file by clicking Download zip file. 


Friday, April 15, 2016

Salesforce Profile Comparison Tool

#FirstBlog :)

I have built one tool in Java which could read profile metadata and generate Comparison Report in excel. The excel sheet generated by tool is very easy to read and has different tabs for various types of permissions. 

Here is the github link for the Tool and instructions on how to use it - 


Profile Comparison Tool