2

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.

if('{!$Profile.Name}' == 'Manager Profile'){
    window.open("/apex/mypage?id={!Opportunity.Id},'_parent');
}
else{
    window.open("/{!Opportunity.Id}",'_parent');
}

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?

3

Why not do the redirect in the Visualforce page itself using the controller or extension for the page?

Call an init method in the page's <apex:page> tag:

<apex:page controller="MyController" action="{!Init}">
 <!-- etc. -->

Then the controller would look something like this:

ApexPages.StandardController sc = null;

public MyController(ApexPages.StandardController sc)
{
  this.sc = sc;
}

public PageReference Init()
{
  Id managerProfile = [select Id from UserProfile where Name = 'Manager Profile' limit 1][0].Id;

  if(UserInfo.GetProfileId() != managerProfile)
  {
    // Not manager, back to the record
    String theUrl = '/' + sc.GetRecord().Get('Id') + '?nooverride=1';
    return new ApexPages.PageReference(theUrl).SetRedirect(true);
  }

  // Stay on the page
  return null;
}

This has been written in the browser so may not be 100% right, but should get you going.

| improve this answer | |
  • This solution helped!! Really appreciate :) – LoveSalesforce Oct 17 '13 at 7:17
  • Not angling for points, but providing info since you're new in these parts. If this solved your issue you should mark it as the accepted answer. You can even do that for questions you ask and answer yourself! – Matt Lacey Oct 18 '13 at 2:15
  • Done :) sorry forgot to do that. – LoveSalesforce Oct 21 '13 at 7:38

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.