1

On my Opportunity object, I have one Record Type that I am looking to redirect to a custom Visualforce Page & Controller. The other Opportunity Record Types can stay defaulted to the standard page layouts.

I have overriden the Opportunity New Button with the Visualforce below which calls my custom controller.

I receive "Cyclical server-side forwards detected" error when testing.

Any ideas what I am doing wrong?

Visualforce:

<apex:page standardController="Opportunity" extensions="SSPNewOpptyRedirect" 
action="{!continueNextPage}">

Apex Class:

public class SSPNewOpptyRedirect {

Opportunity oppty {get; set;}
Id recordTypeA;

public SSPNewOpptyRedirect(ApexPages.StandardController stdController) {
    oppty = (Opportunity)stdController.getRecord();

    recordTypeA = [SELECT Id
                   FROM RecordType
                   WHERE SObjectType = 'Opportunity' AND DeveloperName = 'New_Supply_Side_Platform' LIMIT 1].Id;                                 

}   

public PageReference continueNextPage() {
    PageReference newPage;

    //newPage = Page.SSPOpportunityEdit;
    newPage = new PageReference('/apex/SSPOpportunityEdit');

    if (Oppty.RecordTypeId != recordTypeA)
    {
        String retUrl = '006/e';
        newPage = new PageReference('/' + retUrl);
    }

    if (ApexPages.currentPage().getParameters().get('RecordType') != null) {
        newPage.getParameters().put('RecordType', ApexPages.currentPage().getParameters().get('RecordType'));
    }

    if (ApexPages.currentPage().getParameters().get('retURL') != null) {
        newPage.getParameters().put('retURL', ApexPages.currentPage().getParameters().get('retURL'));
    }

    if (ApexPages.currentPage().getParameters().get('ent') != null) {
        newPage.getParameters().put('ent', ApexPages.currentPage().getParameters().get('ent'));
    }

    newPage.getParameters().put('nooverride', '0');

    return newPage;
}
}

1 Answer 1

0

Your page has gone in to an infinite loop. You need to set 'nooverride' to '1' to break the loop:

newPage.getParameters().put('nooverride', '1');
2
  • I've updated to '1', but still receive the same error. Any ideas?
    – FWSFDC
    Commented Aug 26, 2019 at 21:04
  • 1
    @FWSFDC Maybe your if statement, then? If recordTypeA matches Oppty.RecordTypeId, you're probably returning the same page over again, thus resulting in an infinite loop. You should return null instead of the same page again.
    – sfdcfox
    Commented Aug 26, 2019 at 21:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .