+ Start a Discussion
Claire DomingoClaire Domingo 

hide an opportunity record from owner ( custom coding )

Need advise for any possible custom coding or alternative solution for hiding an opportunity record from the owner.Any help is most appreciated.
Best Answer chosen by Claire Domingo
Suraj PSuraj P
<pre>
<apex:page standardController="Opportunity">
   <apex:detail rendered="{!$User.Id!=Opportunity.OwnerId}" subject="{!Opportunity.Id}" relatedlist="true"/>
   <apex:outputText rendered="{!$User.Id==Opportunity.OwnerId}">You ar not authorized to view this page</apex:outputText>
</apex:page>
</pre>

All Answers

Suraj PSuraj P
Reassign the Opportunity to an Admin, and store the original owner in a custom field. Use the custom field for your queries and such. When needed, assign the record the original owner from the custom field.
Claire DomingoClaire Domingo
Is this possible on custom coding? ( either apex or VF)?
Suraj PSuraj P
You can always override the view action for Opportunity to a VF page that can approve or deny request to view the Opportunity. Please keep in mind, though, that users will still be able to see the opportunity in Reports, via API etc.
Claire DomingoClaire Domingo
Hi Suraj P, your response is most helpful. Your last update I believe is the route where looking for. Do you have a link or a sample coding for this view action that I can use as a start point though? 

Thanks in advance.
Suraj PSuraj P
<pre>
<apex:page standardController="Opportunity">
   <apex:detail rendered="{!$User.Id!=Opportunity.OwnerId}" subject="{!Opportunity.Id}" relatedlist="true"/>
   <apex:outputText rendered="{!$User.Id==Opportunity.OwnerId}">You ar not authorized to view this page</apex:outputText>
</apex:page>
</pre>
This was selected as the best answer
Claire DomingoClaire Domingo
Hi Suraj,

This is a good start for me! This code would hide just the page visibilty of the record but not completely removing him as the record owner right? 

 
Suraj PSuraj P
That is correct. This page would hide all the opportunity records from their respective  owners. If you only want to hide some of the opportunity records, make sure to modify  your code accordingly. As an alternative to using the apex:detail tag, you can use javascript to redirect the user to the standard Opportunity detail page, if you'd prefer that 
 
Claire DomingoClaire Domingo
Got it. Your awesome. Thanks!
Juan Quintero 4Juan Quintero 4
How can I hide the opportunity from all users except from admins?
Juan Quintero 4Juan Quintero 4
Also how can I hide a specific opportunity?