0

I have a controller for a Visualforce page that uses a getter and setter method to initialize a custom object Application__c however it is throwing strange errors that I did not previously get when using getter and setter methods:

Variable is not visible: FormClass.app

Variable does not exist: set

Missing return statement required return type: Application__c

What am I missing here?

public without sharing class FormClass {
    
    //Application
    public Application__c app {
        get {
            if(app == null){    
                app = new Application__c();
            return app;
            }
        set;
        }
    }
}

1 Answer 1

1

Your brackets are screwed up; one of the ones after set are extra, and your if statement is missing a closing bracket. This causes some cascading errors.

public without sharing class FormClass {
    
    //Application
    public Application__c app {
        get {
            if(app == null){    
                app = new Application__c();
            } // this should be here
            return app;
        }
        set;
        // } this one is extra
    }
}
0

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.