function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SF7SF7 

Render Related list only if the logged in user is the owner of the record

Hi ,

I am trying to have a VF page for the Contracts . Org wide everyone has view all Permissions and every one can create contracts but everyone cannot edit it . so i am trying to limit the view of Notes and attchmnets for 3 profiles and the owner of the record. I am succesful with the first part however i am not able to do the second part.So my question is 
1. How can i use th render tag to check if the logged in user is the Owne rof the record. 
2. Can i use rerender or If statement for the Edit button to check if the same conditions as above.
 
<apex:page standardController="Contract" extensions="ContractDetailExtensionController" id="thePage">

<apex:form >
<apex:sectionHeader title="Contract" subtitle="{!Contract.name}"/>
<apex:pageBlock title="Contract">
<apex:pageBlockButtons >
                    <apex:commandButton value="{!$Label.conDetail_Edit}" action="{!edit}" />
                    <apex:commandButton value="{!$Label.conDetail_Delete}" action="{!delete}" />
                    
            </apex:pageBlockButtons>

<apex:pageBlockSection title="Contract Information" columns="2">
<apex:outputField title="Contract Owner" value="{!Contract.OwnerId}"/>
<apex:outputField title="Status" value="{!Contract.Status}"/>
<apex:outputField title="Contract Number" value="{!Contract.ContractNumber}"/>
<apex:outputField title="Contract Start Date" value="{!Contract.StartDate}"/>
<apex:outputField title="Account Name" value="{!Contract.AccountId}"/>
<apex:outputField title="Contract Term (months)" value="{!Contract.ContractTerm}"/>
<apex:outputField title="Customer Signed By" value="{!Contract.CustomerSignedId}"/>
<apex:outputField title="Owner Expiration Notice" value="{!Contract.OwnerExpirationNotice}"/>
<apex:outputField title="Customer Signed Title" value="{!Contract.CustomerSignedTitle}"/>
<apex:outputField title="Company Signed By" value="{!Contract.CompanySignedId}"/>
<apex:outputField title="Customer Signed Date" value="{!Contract.CustomerSignedDate}"/>
<apex:outputField title="Company Signed Date" value="{!Contract.CompanySignedDate}"/>
</apex:pageBlockSection>

<apex:pageBlockSection title="Address Information" columns="2">
<apex:outputField title="Billing Street" value="{!Contract.BillingStreet}"/>
<apex:outputField title="Billing City" value="{!Contract.BillingCity}"/>
<apex:outputField title="Billing State/Province" value="{!Contract.BillingState}"/>
<apex:outputField title="Billing Zip/Postal Code" value="{!Contract.BillingPostalCode}"/>
<apex:outputField title="Billing Country" value="{!Contract.BillingCountry}"/>
</apex:pageBlockSection>


</apex:pageBlock>
</apex:form>

<apex:relatedList list="CombinedAttachments" rendered="{!Checkprofiles}"/>

<apex:relatedList list="OpenActivities" />
<apex:relatedList list="ActivityHistories" />


</apex:page>
 
public with sharing class ContractDetailExtensionController {
private final Contract contract;
    
   
    
    public ContractDetailExtensionController(ApexPages.StandardController stdController) {
        this.contract = (Contract)stdController.getRecord();
    }
    public Boolean getCheckprofiles()
    {
     List<Profile> Prof;
      Prof = [Select id from Profile where Name = 'System Administrator' or Name = 'L2 Support' or Name='Sales Manager - RM'];
      
        for(Profile p :Prof)
        {
            if (UserInfo.getProfileId()== p.Id)
                return true;
        }
        
        return false;
}
}

Thanks
Akhil
Best Answer chosen by SF7
Balaji Chowdary GarapatiBalaji Chowdary Garapati

@Akhil

Try the below tag.,

<apex:relatedList list="CombinedAttachments" rendered="{!IF(Checkprofiles||Contract.OwnerId==$User.ID,True,False)}"/>

and see if works!

Thanks,
Balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati

@Akhil

Try the below tag.,

<apex:relatedList list="CombinedAttachments" rendered="{!IF(Checkprofiles||Contract.OwnerId==$User.ID,True,False)}"/>

and see if works!

Thanks,
Balaji

This was selected as the best answer
SF7SF7
Thanks man , That worked like a charm. I have one more question Do you know Contract history and Items to approve API Names to use for Related list as what ever i try  it gives error 'ItemstoApprove' is not a valid child relationship name for entity Contract 
<Apex:relatedList list="ContractHistory"/>
<apex:relatedList List ="ItemstoApprove"/>