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 "List has no rows for assignment to SObject" error when testing.

Any ideas what I am doing wrong?


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 Name = 'New_Supply_Side_Platform' LIMIT 1].Id;                              


    public PageReference continueNextPage() {
        PageReference newPage;

        newPage = Page.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', '1');

        return newPage;

Visualforce Page:

<apex:page standardController="Opportunity" extensions="SSPNewOpptyRedirect" 
  • 1
    It helps if you include the entirety of the error message, verbatim. Knowing which line is throwing the error (and in which class) is important for debugging.
    – Derek F
    Aug 26, 2019 at 15:02

1 Answer 1


The only query that's casting to a single SObject is the one for Record Type, so that's almost certainly where the error is. Unless you are putting underscores in your Record Type names, you want DeveloperName instead of Name.

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

It's always a good idea to test your queries in DevConsole, Workbench or your IDE to make sure you're getting the results you want.

  • Thanks Thomas. I'm now receiving the following error after making that change. Any ideas? Cyclical server-side forwards detected: /apex/sspopportunityedit?ent=Opportunity&nooverride=1&RecordType=012f2000000DyOh&retURL=%2F006%2Fo
    – FWSFDC
    Aug 26, 2019 at 15:38
  • I don't think you wan't nooverride=1 when redirecting to the VF page for the one record type. Aug 26, 2019 at 15:51
  • Do you propose this condition should be removed entirely, Thomas? I'm not sure what's wrong with the code.
    – FWSFDC
    Aug 26, 2019 at 19:25

You must log in to answer this question.

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