您的最佳选择(方法1)是将字段分隔成FieldSet(请参阅Working with Field Sets in Visualforce),然后使用Visualforce页面覆盖详细信息页面,该页面使用这些FieldSet确定显示哪些字段,并且只显示某些FieldSets查看该页面是该记录的所有者。此方法不需要自定义控制器/扩展,允许您将页面的各个部分隐藏到非所有者,并允许您(或其他管理员)使用拖放式FieldSet编辑器修改每个部分中的字段,这与拖放页面布局编辑器非常相似。
另一种不需要自定义控制器/扩展的方法(方法2)是创建一个Visualforce页面,其中包含您只想显示给所有者的字段,然后仅在运行用户为记录所有者。 YOu然后可以将此Visualforce页面添加到您的页面布局。我不推荐这种方法的原因是,让本页中字段的样式与标准页面布局的其余部分相匹配是一种痛苦。
仅供参考,没有简单的方法(阅读:没有JavaScript hack)显示/隐藏标准页面布局的各个部分而不使用Visualforce。
方法1:
<apex:page standardController="Contact">
<!-- Fields everyone should see -->
<!-- (stored in the 'FieldsEveryoneSees' fieldset) -->
<apex:repeat value="{!$ObjectType.Contact.FieldSets.FieldsEveryoneSees}" var="f">
<apex:outputField value="{!Contact[f]}" /><br/>
</apex:repeat>
<!-- Fields only the Owner should see -->
<!-- (stored in the 'OwnerOnlyFields' fieldset) -->
<apex:repeat value="{!$ObjectType.Contact.FieldSets.OwnerOnlyFields}" var="f"
rendered="{!$User.Id == Contact.OwnerId}">
<apex:outputField value="{!Contact[f]}" /><br/>
</apex:repeat>
</apex:page>
方法2:
<apex:page standardController="Contact" showHeader="false" sidebar="false">
<apex:outputPanel rendered="{!Contact.OwnerId == $User.Id}">
<!-- Fields only the Owner should see -->
<apex:outputField value="{!Contact.LastModifiedDate}"/>
<!-- etc... -->
</apex:outputPanel>
</apex:page>
感谢您的帮助。使用字段集运行良好。我仍然需要做一些事情来使其按照我们想要的方式工作,而不是在部分中显示空白并显示消息。 – Gram