You need to sign in to do that
Don't have an account?

How to Override Opportunity View Link with a VF page for a certain profile?
I have a requirement where I need to override the Opportunity view and to redirect the user of a certain profile to a VF page instead of standard detail page.
I tried something like this:
Created a VF page. Added below script inside it.
<apex:page standardController="Opportunity">
<script>
if('{!$Profile.Name}' == 'Manager Profile'){
window.open("/apex/mypage?id={!Opportunity.Id},'_parent');
}
else{
window.open("/{!Opportunity.Id}",'_parent');
}
</script>
</apex:page>
and in Links , I override the view link of Opportunity with this VF page.
But it works for only manager profile but not for other profiles. The page keeps on loading and loading for other profiles except the manager Profile.
Any idea?
I got the solution. to stop recursion we have to redirect to the dafault detail page like this :
window.open("/{!Opportunity.Id}?nooverride=1",'_parent');
All Answers
When user has different profile, he is redirected to your opportunity view page again, so it is circular. You need create new page for other user, and redirect them to it. In this new page, use apex:detail to show them whole page layout of opportunity.
<apex:page standardController="Opportunity">
<script>
if('{!$Profile.Name}' == 'Manager Profile'){
window.open("/apex/mypage?id={!Opportunity.Id},'_parent');
}
else{
window.open("/apex/newpage?id={!Opportunity.Id}",'_parent');
}
</script>
</apex:page>
I got the solution. to stop recursion we have to redirect to the dafault detail page like this :
window.open("/{!Opportunity.Id}?nooverride=1",'_parent');
Is there a reason you are not just overriding the opportunity view action with this Javascript?
I would always avoid hard coding a profile into a Visualforce page. Profile names can change over time. Profiles can be added/removed. Make sure to put appropriate change management processes into place to avoid unexpected behaviors later.
If I had to hard code the profile into the page, I would not do it as a redirect, I would simply make some conditionally rendered sections of the page and make that based on profile.
We are storing the profile ids in custom label and using them.