+ Start a Discussion
Hardy Vardès Tsialoungou NkoukaHardy Vardès Tsialoungou Nkouka 

Get SObject permissions and Name profil

Hi !
I want to get for each SObjet the Profil Name, PermissionRead, PermissionWrite, PermissionEdit via Apex.
I tried this :
SELECT O.SobjectType, O.PermissionsRead, PermissionWrite, PermissionEdit,  P.ProfileId, P.Profile.Name
FROM ObjectPermissions O, PermissionSet P
WHERE ( P.Id = O.ParentId) AND (O.SobjectType = 'Account')

But it does'nt work !

Can anyone help me?

Thanks

Hardy
Best Answer chosen by Hardy Vardès Tsialoungou Nkouka
Martijn SchwarzerMartijn Schwarzer
Hi Hardy,

I'm not sure why you see the [object Object] values. When I perform that query in SOQLXplorer, I get the following result:

User-added image

If you perform the query in Apex and show the results on screen, I get the following output:

User-added image

I created the overview by creating 1 vf page and 1 apex controller:

VF Page:
 
<apex:page controller="ObjectPermissionsOverviewController">
	<apex:form>
		<apex:pageBlock title="Query results">
			<apex:pageBlockTable value="{!oplist}" var="op" columnsWidth="20%,20%,10%,10%,10%,10%,10%,10%">
				<apex:column headervalue="Profile" value="{!op.Parent.Profile.Name}" />
				<apex:column headervalue="Object" value="{!op.SobjectType}" />
				<apex:column headervalue="Create" value="{!op.PermissionsCreate}" />
				<apex:column headervalue="Delete" value="{!op.PermissionsDelete}" />
				<apex:column headervalue="Edit" value="{!op.PermissionsEdit}" />
				<apex:column headervalue="ModifyAll" value="{!op.PermissionsModifyAllRecords}" />
				<apex:column headervalue="Read" value="{!op.PermissionsRead}" />
				<apex:column headervalue="ViewAll" value="{!op.PermissionsViewAllRecords}" />
			</apex:pageBlockTable>
		</apex:pageBlock>
	</apex:form>
</apex:page>

Apex controller (ObjectPermissionsOverviewController):
 
public class ObjectPermissionsOverviewController {
	public List<ObjectPermissions> oplist{get;set;}
	
	public ObjectPermissionsOverviewController(){
		this.oplist = [select Id, Parent.Profile.Name, SobjectType, PermissionsCreate, PermissionsDelete, PermissionsEdit, PermissionsModifyAllRecords, PermissionsRead, PermissionsViewAllRecords from ObjectPermissions];
	}
	
}

Hope this helps!

Best regards,
Martijn Schwärzer

Ps. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

All Answers

Martijn SchwarzerMartijn Schwarzer
Hi Hardy,

Please try:
SELECT Id, Parent.Profile.Name, SobjectType, PermissionsCreate, PermissionsDelete, PermissionsEdit, PermissionsModifyAllRecords, PermissionsRead, PermissionsViewAllRecords FROM ObjectPermissions

Hope this helps!

Best regards,
Martijn Schwärzer

Ps. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Hardy Vardès Tsialoungou NkoukaHardy Vardès Tsialoungou Nkouka
Hi Martijn !
Thank you for your reply. Pease, look at the result of this request: 
User-added image

Could you tell me  how to get real names of Profil.name?

Thanks,

Hardy
Martijn SchwarzerMartijn Schwarzer
Hi Hardy,

I'm not sure why you see the [object Object] values. When I perform that query in SOQLXplorer, I get the following result:

User-added image

If you perform the query in Apex and show the results on screen, I get the following output:

User-added image

I created the overview by creating 1 vf page and 1 apex controller:

VF Page:
 
<apex:page controller="ObjectPermissionsOverviewController">
	<apex:form>
		<apex:pageBlock title="Query results">
			<apex:pageBlockTable value="{!oplist}" var="op" columnsWidth="20%,20%,10%,10%,10%,10%,10%,10%">
				<apex:column headervalue="Profile" value="{!op.Parent.Profile.Name}" />
				<apex:column headervalue="Object" value="{!op.SobjectType}" />
				<apex:column headervalue="Create" value="{!op.PermissionsCreate}" />
				<apex:column headervalue="Delete" value="{!op.PermissionsDelete}" />
				<apex:column headervalue="Edit" value="{!op.PermissionsEdit}" />
				<apex:column headervalue="ModifyAll" value="{!op.PermissionsModifyAllRecords}" />
				<apex:column headervalue="Read" value="{!op.PermissionsRead}" />
				<apex:column headervalue="ViewAll" value="{!op.PermissionsViewAllRecords}" />
			</apex:pageBlockTable>
		</apex:pageBlock>
	</apex:form>
</apex:page>

Apex controller (ObjectPermissionsOverviewController):
 
public class ObjectPermissionsOverviewController {
	public List<ObjectPermissions> oplist{get;set;}
	
	public ObjectPermissionsOverviewController(){
		this.oplist = [select Id, Parent.Profile.Name, SobjectType, PermissionsCreate, PermissionsDelete, PermissionsEdit, PermissionsModifyAllRecords, PermissionsRead, PermissionsViewAllRecords from ObjectPermissions];
	}
	
}

Hope this helps!

Best regards,
Martijn Schwärzer

Ps. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
This was selected as the best answer
Hardy Vardès Tsialoungou NkoukaHardy Vardès Tsialoungou Nkouka
Thank you very mach Martijn !
That works !!
Urich NOUPIKUrich NOUPIK
Thank Martijn Schwarzer
Very helpfull