You need to sign in to do that
Don't have an account?
Redirecting Opportunity Save to Opportunity Contact Role
I feel like I'm very close to getting this to work. What I'm trying to do it take the user to enter a Opportunity Contact Role page once they save the Opportunity. To do so, I'm overriding the Opportunity View button.
I'm good with the redirct to the Opportunity Contact Role page but the standard Opportunity page is not coming up. I get the following error:
java.lang.IllegalArgumentException: Illegal view ID OpportunityRedirect?id=006M0000004ahc8. The ID must begin with /
Here's my code:
public with sharing class OpportunityRedirect { String oppId; public OpportunityRedirect(ApexPages.StandardController stdController) { //c = stdController; oppId = stdController.getId(); } public PageReference redirect() { PageReference pageDetail = new PageReference ('/p/opp/ContactRoleEditUi/e?oppid=' + oppId + '&retURL=' + oppId); pageDetail.setRedirect(true); OpportunityContactRole[] ocr = [select ContactId, Role, isPrimary from OpportunityContactRole where OpportunityId = :oppId]; system.debug('--------------------- ocr: ' + ocr); if (ocr.size() == 0) return pageDetail; //PageReference pageOpportunity = new PageReference('OpportunityRedirect/?id=' + oppId); PageReference pageOpportunity = new PageReference('OpportunityRedirect'); pageOpportunity.getParameters().put('id',oppId); pageOpportunity.setRedirect(true); return pageOpportunity; } }
<apex:page standardController="Opportunity" extensions="OpportunityRedirect" action="{!redirect}"> <apex:detail /> </apex:page>
Thank you... that apparently fixed one issue but then I ended up with an infinite loop where the page never actually loaded. To fix that, I created a second VF Page without the Action tag and send the user to that new page. So below is the final working code. If anyone has a smarter way to accomplish this, I'd love to hear from you.
Redirect page that the Opportunity View button redirects to:
New view page for the Opportunity which still leverages all the page layout functionality:
Here is the controller to bring it all together:
(modified to add logic the redirect only the Opportunity Owner to the Contact Role page)
All Answers
Visualforce Pages are referenced as /apex/PageName
So the PageReference you're returning should read
Thank you... that apparently fixed one issue but then I ended up with an infinite loop where the page never actually loaded. To fix that, I created a second VF Page without the Action tag and send the user to that new page. So below is the final working code. If anyone has a smarter way to accomplish this, I'd love to hear from you.
Redirect page that the Opportunity View button redirects to:
New view page for the Opportunity which still leverages all the page layout functionality:
Here is the controller to bring it all together:
(modified to add logic the redirect only the Opportunity Owner to the Contact Role page)