I am trying to call a wrapper class which is written independently. I am trying to call the class as a get set variable in a apex class. But getting error while i try to define the class as get set variable. But if I try to call the same class inside the apex class method i am able to access remote wrapper class.

I want to use the class as object on VF page for form filling. We can use the wrapper class inside the main class.But I am trying this out if it is possible or not.

My wrapper class

public class Wrapper{
public String FirstName {get; set;}
public String MiddleName {get; set;}
public String LastName {get; set;}    

Apex class where I call the wrapper

public class myClass{
pubilc Wrapper wap1 {get; set;} // Getting error when defied like this 
public void myfun(){
    Wrapper wap = new Wrapper (); // Able to access class from here  

Error message

Error: Compile Error: Unexpected token 'Wrapper'. at line 2 column 12

  • Are you 100% sure that you are able to access Wrapper inside your method? I'm asking because my guess here would be that your class isn't compiled yet. Try compiling Wrapper first and then save myClass. – Bartosz Śliwiński Mar 20 at 8:37
  • Yes I was able to access the wrapper class inside the apex method. – Anu Mar 20 at 8:52
  • 2
    You have a spelling mistake in access modifier. it should be Public instead of pubilc. Public Wrapper wap1 {get;set;} – 7'7' Mar 20 at 8:54
  • ooo what a sill mistake i made. – Anu Mar 20 at 11:32

The reason why it isn't working in your case is the misspelling in pubilc Wrapper wap1, should be public Wrapper wap1. Worked for me.

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.