1

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:

  1. replaced the standard "New" button with my custom VF page;
  2. in the VF page I've added an action to check and redirect to the correct page;
  3. 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;

}
4

You could have done all of this without any apex code at all:

<apex:page standardController="Opportunity" 
  action="{!IF($Profile.Name=$Label.Partner_Profile_Name, 
    URLFOR($Action.Opportunity.New, null, null, true),
    URLFOR($Page.NewOpportunity, null, null)}"></apex:page>

I'd recommend having the custom Visualforce page be separate so that the redirect is on its own page. It's a little easier to manage this way.

  • Did you mean $Action instead of $ObjectType getting error ApexPagesDescribeSObjectResult.New - Nice tip, thanks – Eric Jun 7 '17 at 15:11
  • @Eric Yeah, I did. – sfdcfox Jun 7 '17 at 15:15
  • Thanks @sfdcfox! Yes, this was definately what I was aiming for. Best! – eclf Jun 12 '17 at 18:01
  • @Eric - Thanks to you as well Eric. $Action was the correct one. Cheers! – eclf Jun 12 '17 at 18:01
2

You need to stop the override by using the nooverride parameter.

Change as follows:

if(user.Profile.Name.equals(PARTNER_PROFILE)){

    PageReference pr = new PageReference('/partner/006/e?retURL=%2Fpartner%2F006%2Fo&nooverried=1');
    return pr;

}
0

Ok, so with the help of @sfdcfox and @Eric, I think I got the answer. I had to tweak the action a little bit.

2 things I had to change:

1) I needed to add a retURL to this URLFOR($Action.Opportunity.New, null, null, true) because the Cancel button on the standard page wasn't doing anything.

2) I replaced this URLFOR($Page.NewOpportunity, null, null)})} for null, because I was getting one of those strange Internal Errors from Salesforce. I think because the page was calling itself, it might've entered some kind of loop.

I ended up with this:

action="{!IF($Profile.Id==PARTNER_PROFILE_ID, URLFOR($Action.Opportunity.New, null, [retURL='/006/o'], true), null)}"

It looks like it's working :)

Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.