You need to sign in to do that
Don't have an account?
Restricting visualforce Page view between profiles
Hey there,
I am very new to visualforce and writing any type of code in general and have come across a major snag. Basically, in my salesforce environment, Account is the main object and everything flows from the Account and is related somewhow. I have created a simple VF page with alot of help from one of the excercises within the VisualForce workbook. This visualforce page shows the Account information as a tab labeled 'details' and all the other custom object/child objects/related lists are other tabs which appear on the page.
Now, different profiles have different object access, the main profile 'destiny standard'', does not have rights to alter or even view the Transaction object.The snag arose when I attempted to view an account from the Destiny Standard profile. I was greeted with an error message, something along the lines of "this profile does not have the rights to access this VF page". Easily solved by adding the visualforce page to the profile, however after adding it to the profile and attempting to access the Accounts object again i was greeted with "Transactions__r' is not a valid child relationship name for entity Account". I figured this was because I had labelled the transactions object as no access within the destiny standard profile.
My question: Is it possible to have a visualforce page, which will have sections that will not appear, should the user not have sufficient permission to access?
This is my accounts VF page:
<apex:page standardController="Account" showHeader="true"
tabStyle="account" >
<style>
.activeTab {background-color: #236FBD; color:white;
background-image:none}
.inactiveTab { background-color: lightgrey; color:black;
background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab="tabdetails"
id="AccountTabPanel" tabClass="activeTab"
inactiveTabClass="inactiveTab">
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail relatedList="false" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying contacts from the {!account.name} account.
Click a contact's name to view his or her details.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:form >
<apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4"
border="1">
<apex:column >
<apex:commandLink rerender="detail">
{!contact.Name}
<apex:param name="cid" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="detail">
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false"
title="false"/>
</apex:outputPanel>
</apex:tab>
<apex:tab label="Destiny Products"
name="Destiny Products" id="tabDestinyProducts">
<apex:relatedList subject="{!account}"
list="Destiny_Products_and_Services__r" />
</apex:tab>
<apex:tab label="Destiny Services"
name="Destiny Services" id="tabDestinyServices">
<apex:relatedList subject="{!account}"
list="Services__r" />
</apex:tab>
<apex:tab label="Transactions"
name="Transactions" id="tabTransactions">
<apex:relatedList subject="{!account}"
list="Transactions__r" />
</apex:tab>
<apex:tab label="Activities" name="OpenActivities"
id="tabOpenAct">
<apex:relatedList subject="{!account}"
list="OpenActivities" />
<apex:relatedList subject="{!account}"
list="ActivityHistories" />
</apex:tab>
<apex:tab label="Compliance Notes"
name="Compliance Notes" id="tabComplianceNotes">
<apex:relatedList subject="{!account}"
list="Compliance_Notes__r" />
</apex:tab>
</apex:tabPanel>
</apex:page>
Any help I could get would be much appreciated. Thank you in advance.
Mikie
Hi,
If your requirement is to display certain sections of the vf page only to certain profiles then follow following approach:
1. You section should have a render attribute (which wil be binded to a boolean variable)
2. Change the value of this boolean in controller depending on the logged in users profile
public String u {get; set;}
u = Userinfo.getUserId();
get the profile name using query something like below:
String profile = [select profilename from profile where user where id=:u];
once you get the profile depending on your req change the bolean varaible to display/not display the sections on vf page
All Answers
Hi
Try this,
<apex:page standardController="Account" showHeader="true"
tabStyle="account" >
<style>
.activeTab {background-color: #236FBD; color:white;
background-image:none}
.inactiveTab { background-color: lightgrey; color:black;
background-image:none}
</style>
<apex:tabPanel switchType="client" selectedTab="tabdetails"
id="AccountTabPanel" tabClass="activeTab"
inactiveTabClass="inactiveTab">
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail relatedList="false" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying contacts from the {!account.name} account.
Click a contact's name to view his or her details.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:form >
<apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4"
border="1">
<apex:column >
<apex:commandLink rerender="detail">
{!contact.Name}
<apex:param name="cid" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="detail">
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false"
title="false"/>
</apex:outputPanel>
</apex:tab>
<apex:tab label="Destiny Products"
name="Destiny Products" id="tabDestinyProducts">
<apex:relatedList subject="{!account}"
list="Destiny_Products_and_Services__r" />
</apex:tab>
<apex:tab label="Destiny Services"
name="Destiny Services" id="tabDestinyServices">
<apex:relatedList subject="{!account}"
list="Services__r" />
</apex:tab>
<apex:tab label="Transactions"
name="Transactions" id="tabTransactions" rendered="{!$ObjectType.Transactions__c.accessible}" >
<apex:relatedList subject="{!account}"
list="Transactions__r" />
</apex:tab>
<apex:tab label="Activities" name="OpenActivities"
id="tabOpenAct">
<apex:relatedList subject="{!account}"
list="OpenActivities" />
<apex:relatedList subject="{!account}"
list="ActivityHistories" />
</apex:tab>
<apex:tab label="Compliance Notes"
name="Compliance Notes" id="tabComplianceNotes">
<apex:relatedList subject="{!account}"
list="Compliance_Notes__r" />
</apex:tab>
</apex:tabPanel>
</apex:page>
Hey I tried the code and got this error message?
Error: Unknown property '$ObjectType.Transactions__c'
Is there anyone that can help me?
Hi,
If your requirement is to display certain sections of the vf page only to certain profiles then follow following approach:
1. You section should have a render attribute (which wil be binded to a boolean variable)
2. Change the value of this boolean in controller depending on the logged in users profile
public String u {get; set;}
u = Userinfo.getUserId();
get the profile name using query something like below:
String profile = [select profilename from profile where user where id=:u];
once you get the profile depending on your req change the bolean varaible to display/not display the sections on vf page
Thankyou so much for your reply. I am very new to VisualForce, as in my time learning can be measured in days rather than weeks. Is there anyway you could give me a small hand on whereabouts I would add this render attribute. My starting goal is to make the transactions__c(child object/related list) tab/object invisible to those without access, yet should someone without access try and access this VF page (I have made it a master account object with everything flowing from it), they are stil able to access it, yet the Transactions Tab is jsut invisible.
Once again thankyou so much for the time you have already provided to me.
Mikie
Hey I worked out how to do it.
I just had to put a rendered tag into the Transactions tab, I used - rendered="{!IF($Profile.Name =='System Administrator', true, (IF($Profile.Name =='Destiny Advanced', true, False)))}" --- to restrict view of the transactions tab from all those except the profiles listed.
Thankyou so much for your time thoough. I really appreciate it.
Mikie