function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MVJMVJ 

Visual Force Redirect

I have a VF page that overrides the new button on a custom object related to opportunites.  When the user clicks to create a new quote we confirm that there exists a Contact role.  If not we redirect the user to the contact role edit page so they can select on.  If on e exists we let them create the quote.  It all works great.

 

However our business partners want us to show a message to the user why they have been redirected to the contact role edit page.

 

Since I can not popup an alert (if someone knows how to do that from a controller please advise) I created a visual force page with the message and a button that will take them to the edit page.

 

This does not work.  When I try to redirect to a VF page the redirect does not work.  What am I missing.  i can redirect to any standard SFDC page not a VF page.

 

Here os the code:

 

Redirect Page:

 

<apex:page standardController="cmgtQuote__c" extensions="DispatcherQuoteNewController" action="{!nullValue(redir.url, urlFor($Action.cmgtQuote__c.New, null, null, true))}"> </apex:page>

 

 The controller:

 

 

public class DispatcherQuoteNewController { public String opptyID {get; set;} public DispatcherQuoteNewController(ApexPages.StandardController controller) { this.controller = controller; } public PageReference gotoOpptyContactEdit(){ string opptyID = ApexPages.currentPage().getParameters().get('oppid'); //string opptyID = '006Q0000003dVVR'; PageReference newPage; newPage = new PageReference('/p/opp/ContactRoleEditUi/e?oppid='+opptyID+'&retURL=/'+opptyID); newPage.getParameters().put('nooverride', '1'); return newPage.setRedirect(true); } public PageReference getRedir() { //string opptyID = '006Q0000003dVVR'; string opptyID = ApexPages.currentPage().getParameters().get('CF00N30000002Bott_lkid'); PageReference newPage; string newQuoteURL = '/a0E/e?CF00N30000002Bott=Test&CF00N30000002Bott_lkid='+opptyID+'&retURL=%2F'+opptyID; if (hasOpportunityContact(opptyID)) { newPage = new PageReference('/a0E/e?CF00N30000002Bott=Test&CF00N30000002Bott_lkid='+opptyID+'&retURL=%2F'+opptyID); newPage.getParameters().put('nooverride', '1'); return newPage.setRedirect(true); } else { //newPage = new PageReference('/p/opp/ContactRoleEditUi/e?oppid='+opptyID+'&retURL=/'+opptyID); //newPage = new PageReference('/home/home.jsp'); newPage = new PageReference('/apex/OpportunityContactRoleError'); newPage.getParameters().put('nooverride', '1'); newPage.getParameters().put('oppid', opptyID); return newPage.setRedirect(true); } } private final ApexPages.StandardController controller; public boolean hasOpportunityContact(string opptyid){ Boolean rv = false; OpportunityContactRole [] ocr = [Select Id, OpportunityId From OpportunityContactRole Where OpportunityId = :opptyid]; if (ocr.size() > 0) {rv = true;} return rv; } }

 

When I try to redirect to the Apex Page it does not redirect. 

 

Thanks

 

 

 

uptime_andrewuptime_andrew

What about doing it in the controller, rather than the visualforce page?

 

 

public class DispatcherQuoteNewController { public String opptyID {get; set;} public DispatcherQuoteNewController(ApexPages.StandardController controller) { this.controller = controller; if([some condition]) { redirect(); } } public PageReference redirect() { PageReference pg = new PageReference([somepage]); pg.setRedirect(true); return pg; }

 

 

}