0

I'm trying to access a wrapper class from a helper class.

MyHelper:

public with sharing class MyHelper {

    public class someWrapper {

        public Opportunity  someOpportunity {get; set;}
        public Boolean      someBoolean     {get; set;}

        public someWrapper(Opportunity opp){

            someOpportunity = opp;
            someBoolean = true;

        }

    }

}

I tried to get access to my someWrapper from MyHelper but getting this error

Invalid type: helper.someWrapper

Here is how I have tried:

ControllerExtension:

Opportunity  o = new Opportunity()l
MyHelper helper = new MyHelper();
for(Opportunity o : [select...])
{ 
    helper.someWrapper = new helper.someWrapper(o); 
}

2 Answers 2

3

Classes are static, meaning there is only ever a single instance of a class definition. This means that you must refer to the class using its fully qualified name:

MyHelper.someWrapper = new MyHelper.someWrapper(o); 
0

if you want to create an instance of wrapper class object then use

Opportunity  o = new Opportunity();
MyHelper.someWrapper wrapperObj = new MyHelper.someOpportunity(o); 

ie: you need a variable 'wrapperObj' to instantiate to.

If class MyHelper has an object of wrapper as in

public with sharing class MyHelper {
    someWrapper someWrapperObj {get; set;}

    public class someWrapper {
       public Opportunity  someOpportunity {get; set;}
       ....
       ....
   }
}

Then in controller you could use

Opportunity  o = new Opportunity();
MyHelper helper = new MyHelper();
for(Opportunity o : [select...])
{ 
    helper.someWrapperObj = new MyHelper.someWrapper(o); 
}

You must log in to answer this question.

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