Custom Permission

Hey Guys, Once again brothers are back .

Have you ever build any vf page with Buttons Edit / Clone/ Save /Cancel ??

If yes,  Have you ever tried to assign this page to all users ?

If yes, Have you ever worried about permissions they have on the respective object to do clone/ Edit / Save / Cancel ??

Ok. let me explain it clear.

Any user in salesforce can able to access the whole page or not able to access the page.

Have you ever tried to give the access to the part of the page , based on User permissions??

Yes!!! If you want to give access to pare of the page based on login user access , you are at right place.

Lets get into the functionality. How it works both theoretical and followed by practical way.

Step 1: Create a Permission Set with Some Label “MyCustomPermission

Step 2: Go to Permission Set (SetUp > Permission Set(Type Permission Set in Quick Find))

Step 3: Open any Existing Permission Set (For Ex: MyPermissionSet)and Click on Custom Permission

Step 4: There you can able to  add the Custom Permission that you have created at Step 1(In Our ex: MyCustomPermission)

Step 5: Add Users to the Permission Set by clicking on Manage User.

Ex : Lets add X, Y and Z to our Permission Set (in our Case its MyPermissionSet)

Step 5:  Select the Custom Permission  and Click on Save. (We almost Done( 🙂 )

Step 6: Now create on VF Page and show the data to the User.

Step 7: Before dive into the topic, Let you explain something related to Render

Step 7.1 : Rendered = “True” Shows the Piece of the page  to the Users

                    Rendered = “False” Hides the Piece of the Page to the Users

Step 8: Give Rendered = “{!(IF($Permission.MyCustomPermission,TRUE,TRUE))}”

(Ex  :  <apex:CommandButton value=”Save” action”{!save}” Rendered = “{!(IF($Permission.MyCustomPermission,TRUE,TRUE))}” / >)

Let me Explain Exactly what Step 8 does:

1 ) It will check the Login User Permission Set first

2 ) It will check each & every  Permission Set t o which that User belongs

3 ) Check  whether the Permission Set has the “MyCustomPermission” as the Custom Permission

4) If the any of the Permission Set of that User have Custom Permission “MyCustomPermission” then the block of code will shown to the user.

Other wise, it  doesn’t.

In our Cases lets take i am  logging as a  User “X”

That  User have  Permission Set  called, “MyPermissionSet

MyPermissionSet” have  Custom Permission Called “MyCustomPermission

So as per our example :

<apex:CommandButton value=”Save” action”{!save}” Rendered = “{!(IF($Permission.MyCustomPermission,TRUE,TRUE))}” / >

This button will visible the User X.

Conclusion: The above ComomandButton says , “Other than X,  Y and Z , no other user is allowed to see Save the button”

That’s all Folks. I hope this article will help you guys a lot.

Lets discuss some other new topic in the Next meeting.

Comments are always welcome 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s