I have 2 user profiles: internal user and partner user (partner portal). I want to have separate behaviours when each user clicks on the Opportunity New button, to create a new opportunity:
internal user clicks on Opportunity New button - redirect to a custom visualforce page;
partner user clicks on Opportunity New button - redirect to a custom the standard opportunity edit page;
I have:
- replaced the standard "New" button with my custom VF page;
- in the VF page I've added an action to check and redirect to the correct page;
- in the controller, the method checks the context user and if it's a partner user, redirects to the standard opportunity edit page.
This works fine for internal user; for the partner user, it does redirect to the standard page but, for some reason, it gets into some kind of loop and the page never actually loads.
I wonder if the link I am redirecting to is correct or if there's something I am doing wrong.
Here's a snippet of the code:
VF Page:
<apex:page standardController="Opportunity" extensions="OpportunityController" tabStyle="Opportunity" action="{!redirectForPartner}">
</apex:page>
Controller:
public PageReference redirectForPartner(){
User user;
Id userId = UserInfo.getUserId();
if(userId != null){
user = [Select Id, Name, Email, Username, ProfileId, Profile.Name From User Where Id =: userId];
}
if(user.Profile.Name.equals(PARTNER_PROFILE)){
PageReference pr = new PageReference('/partner/006/e?retURL=%2Fpartner%2F006%2Fo');
return pr;
}
return null;
}