0

I am not sure what is wrong in my code, but I get the following compile error:

Error: Non-void method might not return a value or might have statement after a return statement. at line 11 column 9

Below is my VF Page

<apex:page standardcontroller="Revenue_Reports__c" extensions="VF_Controller_CasePgLayout" />

Below is my controller class

public with sharing class VF_Controller_FASPgLayout {

    public Revenue_Reports__c R1;

        public void VF_Controller_FASPgLayout(ApexPages.StandardController controller) {
            this.R1 = (Revenue_Reports__c)controller.getRecord();
        }

        public PageReference FASpageRedirect() {
            if(ApexPages.currentPage().getParameters().get('RecordType') == '01I230000008cX9'){
                PageReference pageRef = new PageReference('/apex/RevenueReports_FAS_VfPge');
                return pageRef;
            }
            else if(ApexPages.currentPage().getParameters().get('AccountId') == null){
                PageReference pageRef2 = new PageReference('https://cs28.salesforce.com/a4T/o');
                return pageRef2;
            }
        }
    }
}

Can someone tell me what is that i am missing or why is this error message appearing?

1 Answer 1

2

You have basically the following structure in your FASpageRedirect method:

public pageReference myFunction()
{
    if (conditionA)
        return pageReferenceA;
    else if (conditionB)
        return pageReferenceB;
}

So what happens if neither conditionA nor conditionB are true? You need an unconditional return.

public pageReference myFunction()
{
    if (conditionA)
        return pageReferenceA;
    else if (conditionB)
        return pageReferenceB;
    return someFallbackPageReference; // you need a fallback plan
}

Also note that building your link using cs28.salesforce.com will not work when you deploy to your production environment, and likely won't even work during staging. You should construct your links more programmatically.

PageReference pageReferenceA = Page.RevenueReports_FAS_VfPge;
PageReference pageReferenceB = '/' + SObjectType.MyObject__c.getKeyPrefix() + '/o';

Replace MyObject__c above with the actual API Name of your object.

You must log in to answer this question.