0

Trying to create a custom controller for a VF page following is the code for Apex class -

public class MyCustomVFPage_CTR {
    public String ObjectId {get;set;}
    public String ResponseCode {get;set;}
    public MyCustomVFPage_CTR () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        ResponseCode = ApexPages.currentPage().getParameters().get('ResponseCode');
    }
    public PageReference InitPage() {
        List<Customer_Issue__c> CustomerIssues = [SELECT Id, Status__c FROM Customer_Issue__c WHERE Id=:ObjectId LIMIT 1];
        if(!CustomerIssues.IsEmpty()){
            CustomerIssues[0].Status__c = ResponseCode;
            UPDATE CustomerIssues;
        }
    }
}

Calling this in a VF page -

<apex:page id="Page" showHeader="false" controller="MyCustomVFPage_CTR" action="{!InitPage}" cache="false">
    <apex:form>
        Thank you for your custom.
    </apex:form>
</apex:page>

Getting following error -

Missing return statement required return type: System.PageReference

Tried to write a separate method but no luck.

2

This method:

public PageReference InitPage() {
    List<Customer_Issue__c> CustomerIssues = [SELECT Id, Status__c FROM Customer_Issue__c WHERE Id=:ObjectId LIMIT 1];
    if(!CustomerIssues.IsEmpty()){
        CustomerIssues[0].Status__c = ResponseCode;
        UPDATE CustomerIssues;
    }
}

must return something (as it is not marked as returning void and so the compiler complains) and for the case where you don't want to move to a different page you return null:

public PageReference InitPage() {
    List<Customer_Issue__c> CustomerIssues = [SELECT Id, Status__c FROM Customer_Issue__c WHERE Id=:ObjectId LIMIT 1];
    if(!CustomerIssues.IsEmpty()){
        CustomerIssues[0].Status__c = ResponseCode;
        UPDATE CustomerIssues;
    }
    // Add the line below
    return null;
}

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.