0
<apex:page standardController="Opportunity" extensions="VVP_OpportunityController"  lightningStylesheets="True" action="{!OppRedirect}">



public PageReference OppRedirect(){
    if(oppRed.RecordTypeId == '0121w00000017YWAAY'){
        PageReference parque = new PageReference('/apex/VVP_OpportunityDetailNew');                                                   
        return parque;
    }else{  
        PageReference smartPricing = new PageReference('/006/e?retURL=%2F'+oppRed.AccountId+'&RecordType='+oppRed.RecordTypeId+'&ent=Opportunity&nooverride=1');
        return smartPricing;
    }
}

And i want to my Visualforce Page open the correct PageReference, the else condition is working fine. In the if Condition i'm retrive the following error:

Cyclical server-side forwards detected: /apex/VVP_OpportunityDetailNew

Can someone help me?

  • This occurs when you return the pagereference from apex of a page that you are already on. What page is the apex you posted associated with? – Anurag Dec 18 '19 at 15:14
  • New standard button, i want that after i press new button i want that de visualforce page or open in the Visualforce page that i'm standing or open the standard menu of new – João Gonzaga Dec 18 '19 at 15:18
  • Is the button on standard page layout or on a VF Page? – Anurag Dec 18 '19 at 15:24
  • try setting parque.setRedirect(true) in if clause. – Rohit Mourya Dec 18 '19 at 15:25
  • In a Standard page layout – João Gonzaga Dec 18 '19 at 15:30
0

Due to action on the page, your page is being redirected itself infinite times. If you don't want to redirect your page,

Below code is the problem here.

if(oppRed.RecordTypeId == '0121w00000017YWAAY'){
    PageReference parque = new PageReference('/apex/VVP_OpportunityDetailNew');                                                   
    return parque;
}

Just replace that with this:

if(oppRed.RecordTypeId == '0121w00000017YWAAY'){                                                   
    return null;
}

So you will stay on the same page.

Also,

Do not hard code Ids in your code.

You can get record type id by its name using the below code.

Id devRecordTypeId = Schema.SObjectType.ObjectApiName.getRecordTypeInfosByName().get('RecordTypeName').getRecordTypeId();
| improve this answer | |
0

This happens when your page goes into infinite loop. Try putting parameter to your PageReference variable as below:

parque.getParameters().put('nooverride', '1');
| improve this answer | |
  • Show the same error – João Gonzaga Dec 18 '19 at 15:32
  • Does one of your condition returns the user to same page? – Rohit Mourya Dec 18 '19 at 15:35

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.