1

I want to access public Id recordtype; variable in line no - 18 SOQL . How to do that.

public with sharing class RFPController{

        public Id recordtype;
        public RFPController(ApexPages.StandardController controller) {
            recordtype = ApexPages.currentPage().getParameters().get('RecordType');
            }
        }

        public class CustomPackageWrapper {

            RFPController rfp;
            Set<String> uniqueCustomObjectSet = new Set<String>(); 
            public Id some;

            public List<SelectOption> getItems() {
                some = rfp.recordtype;

                String Recordtypename= String.valueOf([SELECT DeveloperName FROM RecordType where id=: some]) ;
                system.debug('Recordtypename' + Recordtypename);
                string recordtypefinalname = null;


                if(Recordtypename=='Business Office Custom')
                {
                    recordtypefinalname='Bussiness';
                } else{
                    if(Recordtypename=='Business Office Network'){
                        recordtypefinalname='Network'; 
                    }
                }
                List<Custom_Package__c> bpck = new List<Custom_Package__c>([Select s.Id,s.Name From Custom_Package__c s where s.RecordType.Name =:recordtypefinalname]);

                List<SelectOption> options = new List<SelectOption>();
                system.debug('recordtypefinalname' + recordtypefinalname);
                for(Custom_Package__c sl:[Select s.Id,s.Name From Custom_Package__c s where s.RecordType.Name =:recordtypefinalname order by s.Name])
                {
                    uniqueCustomObjectSet.add(sl.Name);
                }
                List<String> uniqueCustomObjectList = new List<String>(uniqueCustomObjectSet);

                for(integer i=0; i<uniqueCustomObjectList.size(); i++){
                    options.add(new SelectOption(uniqueCustomObjectList[i],uniqueCustomObjectList[i]));
                }
                return options;
            }

            public CustomPackageWrapper(Custom_Package__c cp)
            {
            cp = new Custom_Package__c();
                for (Custom_Package__c cp1 : [select Id,Counter__c, Market__c, state__c,First_Issue__c,Last_Issue__c,Circulation__c,Space_Unit__c,Space_Discount__c, Per_Unit_Open_Rate__c from Custom_Package__c where Name IN:discountSchedule order by Market__c]) {
                    this.cp = cp;

                }
                this.checked = false;

            }

        }
    }
2

Your wrapper constructor needs to be passed and hold on to a reference to the outer class:

public class CustomPackageWrapper {
    RFPController rfp;
    ...
    public CustomPackageWrapper(RFPController rfp, Custom_Package__c cp) {
        this.rfp = rfp;
        ...
    }
    ...
}

and then when you construct those wrapper class instances in the RFPController constructor or an RFPController method this provides the reference you need:

public with sharing class RFPController {
    ...
        CustomPackageWrapper w = new CustomPackageWrapper(this, cp);
    ...
}
  • If you intend to store the reference of only one variable, you can declare only that variable and pass value in constructor instead of whole class. – RajeshShah Dec 4 '15 at 8:51
  • 1
    @RajeshShah Fair point, though in my experience you often end up referencing multiple fields from the outer class in the inner class. Passing the reference to the outer class also mirrors how non-static Java inner classes work so is a familiar pattern to anyone who also uses Java. – Keith C Dec 4 '15 at 8:55

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.