Adding a Wrapper Class to an External Class

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












4














I am confused about what is happening in a small section of some code. I have a class that has a wrapper class inside it. There is an external class that calls this wrapper class Models.add(new CheckItemsClass(...)) The part that confuses me is that the Models.cls does not have any reference or instance of CheckItemsClass. So how are we able to add a new CheckItemsClass to the Models.cls?



public class ChecklistController
public List<CheckItemClass> fillItems(Credit_review__c obj)
Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
return Models;

public class CheckItemClass
public string item get;set;
public string notes get;set;
public boolean flag get;set;
public CheckItemClass(string i,string n,boolean f)
this.item = i;
this.notes = n;
this.flag = f;




public without sharing class Models
public static void mdlEncinitas(List<WC_Credit_Decision__c> wcObs)...
public static void mdlDataV1(List<WC_Credit_Decision__c> wcObs, List<ID> wccdIds) ...
public static void mdlDataV2(List<WC_Credit_Decision__c> wcObs, List<ID> wccdIds) ...
public static void mdlEncinitasRecommender(WC_Credit_Decision__c wcOb, Integer score10pt, Integer score, String productionChannel, Double grossSalesRunRate, Double judgmentTotalAmt, Integer maxTib, Double avgOfAvgDailyBal, Double bkDateYrs, Integer maxFICO, String sicCode, NF_SIC_4__c sicOb, Credit_Review__c crOb, WC_Buy_Rate__c brOb, Boolean lenderMissing, Double maxNegDaysLst3Mnths, String oppType, List<Decision_Attribute__c> decisionAttr, Double maxNegDaysEver, Double maxNSFsEver) ...
public static void mdlEncinitasRun(ID wcId, WC_Credit_Decision__c wcOb, Credit_Review__c crOb, Opportunity oppOb, List<Monthly_Review__c> mrObs,NF_SIC_4__c sicOb, Account acctOb, WC_Buy_Rate__c brOb, Boolean brokerMissing, Map<Id,List<Credit_Review_Monthly_Ledger__c>> CR_ledgers_map, List<Decision_Attribute__c> decisionAttr)...










share|improve this question


























    4














    I am confused about what is happening in a small section of some code. I have a class that has a wrapper class inside it. There is an external class that calls this wrapper class Models.add(new CheckItemsClass(...)) The part that confuses me is that the Models.cls does not have any reference or instance of CheckItemsClass. So how are we able to add a new CheckItemsClass to the Models.cls?



    public class ChecklistController
    public List<CheckItemClass> fillItems(Credit_review__c obj)
    Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
    return Models;

    public class CheckItemClass
    public string item get;set;
    public string notes get;set;
    public boolean flag get;set;
    public CheckItemClass(string i,string n,boolean f)
    this.item = i;
    this.notes = n;
    this.flag = f;




    public without sharing class Models
    public static void mdlEncinitas(List<WC_Credit_Decision__c> wcObs)...
    public static void mdlDataV1(List<WC_Credit_Decision__c> wcObs, List<ID> wccdIds) ...
    public static void mdlDataV2(List<WC_Credit_Decision__c> wcObs, List<ID> wccdIds) ...
    public static void mdlEncinitasRecommender(WC_Credit_Decision__c wcOb, Integer score10pt, Integer score, String productionChannel, Double grossSalesRunRate, Double judgmentTotalAmt, Integer maxTib, Double avgOfAvgDailyBal, Double bkDateYrs, Integer maxFICO, String sicCode, NF_SIC_4__c sicOb, Credit_Review__c crOb, WC_Buy_Rate__c brOb, Boolean lenderMissing, Double maxNegDaysLst3Mnths, String oppType, List<Decision_Attribute__c> decisionAttr, Double maxNegDaysEver, Double maxNSFsEver) ...
    public static void mdlEncinitasRun(ID wcId, WC_Credit_Decision__c wcOb, Credit_Review__c crOb, Opportunity oppOb, List<Monthly_Review__c> mrObs,NF_SIC_4__c sicOb, Account acctOb, WC_Buy_Rate__c brOb, Boolean brokerMissing, Map<Id,List<Credit_Review_Monthly_Ledger__c>> CR_ledgers_map, List<Decision_Attribute__c> decisionAttr)...










    share|improve this question
























      4












      4








      4







      I am confused about what is happening in a small section of some code. I have a class that has a wrapper class inside it. There is an external class that calls this wrapper class Models.add(new CheckItemsClass(...)) The part that confuses me is that the Models.cls does not have any reference or instance of CheckItemsClass. So how are we able to add a new CheckItemsClass to the Models.cls?



      public class ChecklistController
      public List<CheckItemClass> fillItems(Credit_review__c obj)
      Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
      return Models;

      public class CheckItemClass
      public string item get;set;
      public string notes get;set;
      public boolean flag get;set;
      public CheckItemClass(string i,string n,boolean f)
      this.item = i;
      this.notes = n;
      this.flag = f;




      public without sharing class Models
      public static void mdlEncinitas(List<WC_Credit_Decision__c> wcObs)...
      public static void mdlDataV1(List<WC_Credit_Decision__c> wcObs, List<ID> wccdIds) ...
      public static void mdlDataV2(List<WC_Credit_Decision__c> wcObs, List<ID> wccdIds) ...
      public static void mdlEncinitasRecommender(WC_Credit_Decision__c wcOb, Integer score10pt, Integer score, String productionChannel, Double grossSalesRunRate, Double judgmentTotalAmt, Integer maxTib, Double avgOfAvgDailyBal, Double bkDateYrs, Integer maxFICO, String sicCode, NF_SIC_4__c sicOb, Credit_Review__c crOb, WC_Buy_Rate__c brOb, Boolean lenderMissing, Double maxNegDaysLst3Mnths, String oppType, List<Decision_Attribute__c> decisionAttr, Double maxNegDaysEver, Double maxNSFsEver) ...
      public static void mdlEncinitasRun(ID wcId, WC_Credit_Decision__c wcOb, Credit_Review__c crOb, Opportunity oppOb, List<Monthly_Review__c> mrObs,NF_SIC_4__c sicOb, Account acctOb, WC_Buy_Rate__c brOb, Boolean brokerMissing, Map<Id,List<Credit_Review_Monthly_Ledger__c>> CR_ledgers_map, List<Decision_Attribute__c> decisionAttr)...










      share|improve this question













      I am confused about what is happening in a small section of some code. I have a class that has a wrapper class inside it. There is an external class that calls this wrapper class Models.add(new CheckItemsClass(...)) The part that confuses me is that the Models.cls does not have any reference or instance of CheckItemsClass. So how are we able to add a new CheckItemsClass to the Models.cls?



      public class ChecklistController
      public List<CheckItemClass> fillItems(Credit_review__c obj)
      Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
      return Models;

      public class CheckItemClass
      public string item get;set;
      public string notes get;set;
      public boolean flag get;set;
      public CheckItemClass(string i,string n,boolean f)
      this.item = i;
      this.notes = n;
      this.flag = f;




      public without sharing class Models
      public static void mdlEncinitas(List<WC_Credit_Decision__c> wcObs)...
      public static void mdlDataV1(List<WC_Credit_Decision__c> wcObs, List<ID> wccdIds) ...
      public static void mdlDataV2(List<WC_Credit_Decision__c> wcObs, List<ID> wccdIds) ...
      public static void mdlEncinitasRecommender(WC_Credit_Decision__c wcOb, Integer score10pt, Integer score, String productionChannel, Double grossSalesRunRate, Double judgmentTotalAmt, Integer maxTib, Double avgOfAvgDailyBal, Double bkDateYrs, Integer maxFICO, String sicCode, NF_SIC_4__c sicOb, Credit_Review__c crOb, WC_Buy_Rate__c brOb, Boolean lenderMissing, Double maxNegDaysLst3Mnths, String oppType, List<Decision_Attribute__c> decisionAttr, Double maxNegDaysEver, Double maxNSFsEver) ...
      public static void mdlEncinitasRun(ID wcId, WC_Credit_Decision__c wcOb, Credit_Review__c crOb, Opportunity oppOb, List<Monthly_Review__c> mrObs,NF_SIC_4__c sicOb, Account acctOb, WC_Buy_Rate__c brOb, Boolean brokerMissing, Map<Id,List<Credit_Review_Monthly_Ledger__c>> CR_ledgers_map, List<Decision_Attribute__c> decisionAttr)...







      apex class wrapper-class inner-class






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 14 at 20:59









      Olivia

      1,286422




      1,286422




















          3 Answers
          3






          active

          oldest

          votes


















          6














          Somewhere else in the local context, there is a variable declaration that's shadowing the class Models.



          Example:



          public class TestQ242685 
          public class InnerClass



          public static void runTest()
          List<InnerClass> SomeOtherClass = new List<InnerClass>();

          SomeOtherClass.add(new InnerClass());
          System.debug(SomeOtherClass);



          public class SomeOtherClass
          // No `add()` method!



          Call TestQ242685.runTest() and sure enough, you'll see




          16:04:08:034 USER_DEBUG [10]|DEBUG|(InnerClass:)




          You've got a List<CheckItemClass> Models declared somewhere.






          share|improve this answer




















          • ah you are right, it was at the very top. I totally missed it. thank you!
            – Olivia
            Dec 14 at 21:11


















          5














          You seem to have a name shadowing here.



          This code is adding CheckItemClass objects in a List<CheckItemClass> which is most likely declared in your controller as:



          List<CheckItemClass> Models = new List<CheckItemClass>();`


          And from documentation:




          In particular it is legal for a variable, method, and a class within a class to have the same name.




          So that's why you are not getting any compile errors with same names. It's always a good idea to keep names specific to the context.



          And it's the same variable that's being used in your fillItems() method as below:



          public List<CheckItemClass> fillItems(Credit_review__c obj)
          Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
          return Models;



          So Models.add() is not really calling any method in the Models class, but the List.add() method. Also refer to the return statement which confirms as what you are returning.






          share|improve this answer






















          • thank you! I realized I missed the List<CheckItemClass> Models = new List<CheckItemClass>();. This is a good example of how important naming is. It can get easily confusing!
            – Olivia
            Dec 14 at 21:11


















          3














          Name shadowing can take many forms...



          Here is my personal favorite (as I have made this mistake more than once wrto name shadowing) from the lazy loading pattern...



          public Contact contacts 
          get
          if (contacts == null)
          Contact contacts = [SELECT ... FROM Contact WHERE ...]; //oops - declared new vbl!

          return contacts;
          private set;


          if (contacts.isEmpty()) ... . // null pointer exception!





          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "459"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f242685%2fadding-a-wrapper-class-to-an-external-class%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            6














            Somewhere else in the local context, there is a variable declaration that's shadowing the class Models.



            Example:



            public class TestQ242685 
            public class InnerClass



            public static void runTest()
            List<InnerClass> SomeOtherClass = new List<InnerClass>();

            SomeOtherClass.add(new InnerClass());
            System.debug(SomeOtherClass);



            public class SomeOtherClass
            // No `add()` method!



            Call TestQ242685.runTest() and sure enough, you'll see




            16:04:08:034 USER_DEBUG [10]|DEBUG|(InnerClass:)




            You've got a List<CheckItemClass> Models declared somewhere.






            share|improve this answer




















            • ah you are right, it was at the very top. I totally missed it. thank you!
              – Olivia
              Dec 14 at 21:11















            6














            Somewhere else in the local context, there is a variable declaration that's shadowing the class Models.



            Example:



            public class TestQ242685 
            public class InnerClass



            public static void runTest()
            List<InnerClass> SomeOtherClass = new List<InnerClass>();

            SomeOtherClass.add(new InnerClass());
            System.debug(SomeOtherClass);



            public class SomeOtherClass
            // No `add()` method!



            Call TestQ242685.runTest() and sure enough, you'll see




            16:04:08:034 USER_DEBUG [10]|DEBUG|(InnerClass:)




            You've got a List<CheckItemClass> Models declared somewhere.






            share|improve this answer




















            • ah you are right, it was at the very top. I totally missed it. thank you!
              – Olivia
              Dec 14 at 21:11













            6












            6








            6






            Somewhere else in the local context, there is a variable declaration that's shadowing the class Models.



            Example:



            public class TestQ242685 
            public class InnerClass



            public static void runTest()
            List<InnerClass> SomeOtherClass = new List<InnerClass>();

            SomeOtherClass.add(new InnerClass());
            System.debug(SomeOtherClass);



            public class SomeOtherClass
            // No `add()` method!



            Call TestQ242685.runTest() and sure enough, you'll see




            16:04:08:034 USER_DEBUG [10]|DEBUG|(InnerClass:)




            You've got a List<CheckItemClass> Models declared somewhere.






            share|improve this answer












            Somewhere else in the local context, there is a variable declaration that's shadowing the class Models.



            Example:



            public class TestQ242685 
            public class InnerClass



            public static void runTest()
            List<InnerClass> SomeOtherClass = new List<InnerClass>();

            SomeOtherClass.add(new InnerClass());
            System.debug(SomeOtherClass);



            public class SomeOtherClass
            // No `add()` method!



            Call TestQ242685.runTest() and sure enough, you'll see




            16:04:08:034 USER_DEBUG [10]|DEBUG|(InnerClass:)




            You've got a List<CheckItemClass> Models declared somewhere.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 14 at 21:05









            David Reed

            29.5k61746




            29.5k61746











            • ah you are right, it was at the very top. I totally missed it. thank you!
              – Olivia
              Dec 14 at 21:11
















            • ah you are right, it was at the very top. I totally missed it. thank you!
              – Olivia
              Dec 14 at 21:11















            ah you are right, it was at the very top. I totally missed it. thank you!
            – Olivia
            Dec 14 at 21:11




            ah you are right, it was at the very top. I totally missed it. thank you!
            – Olivia
            Dec 14 at 21:11













            5














            You seem to have a name shadowing here.



            This code is adding CheckItemClass objects in a List<CheckItemClass> which is most likely declared in your controller as:



            List<CheckItemClass> Models = new List<CheckItemClass>();`


            And from documentation:




            In particular it is legal for a variable, method, and a class within a class to have the same name.




            So that's why you are not getting any compile errors with same names. It's always a good idea to keep names specific to the context.



            And it's the same variable that's being used in your fillItems() method as below:



            public List<CheckItemClass> fillItems(Credit_review__c obj)
            Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
            return Models;



            So Models.add() is not really calling any method in the Models class, but the List.add() method. Also refer to the return statement which confirms as what you are returning.






            share|improve this answer






















            • thank you! I realized I missed the List<CheckItemClass> Models = new List<CheckItemClass>();. This is a good example of how important naming is. It can get easily confusing!
              – Olivia
              Dec 14 at 21:11















            5














            You seem to have a name shadowing here.



            This code is adding CheckItemClass objects in a List<CheckItemClass> which is most likely declared in your controller as:



            List<CheckItemClass> Models = new List<CheckItemClass>();`


            And from documentation:




            In particular it is legal for a variable, method, and a class within a class to have the same name.




            So that's why you are not getting any compile errors with same names. It's always a good idea to keep names specific to the context.



            And it's the same variable that's being used in your fillItems() method as below:



            public List<CheckItemClass> fillItems(Credit_review__c obj)
            Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
            return Models;



            So Models.add() is not really calling any method in the Models class, but the List.add() method. Also refer to the return statement which confirms as what you are returning.






            share|improve this answer






















            • thank you! I realized I missed the List<CheckItemClass> Models = new List<CheckItemClass>();. This is a good example of how important naming is. It can get easily confusing!
              – Olivia
              Dec 14 at 21:11













            5












            5








            5






            You seem to have a name shadowing here.



            This code is adding CheckItemClass objects in a List<CheckItemClass> which is most likely declared in your controller as:



            List<CheckItemClass> Models = new List<CheckItemClass>();`


            And from documentation:




            In particular it is legal for a variable, method, and a class within a class to have the same name.




            So that's why you are not getting any compile errors with same names. It's always a good idea to keep names specific to the context.



            And it's the same variable that's being used in your fillItems() method as below:



            public List<CheckItemClass> fillItems(Credit_review__c obj)
            Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
            return Models;



            So Models.add() is not really calling any method in the Models class, but the List.add() method. Also refer to the return statement which confirms as what you are returning.






            share|improve this answer














            You seem to have a name shadowing here.



            This code is adding CheckItemClass objects in a List<CheckItemClass> which is most likely declared in your controller as:



            List<CheckItemClass> Models = new List<CheckItemClass>();`


            And from documentation:




            In particular it is legal for a variable, method, and a class within a class to have the same name.




            So that's why you are not getting any compile errors with same names. It's always a good idea to keep names specific to the context.



            And it's the same variable that's being used in your fillItems() method as below:



            public List<CheckItemClass> fillItems(Credit_review__c obj)
            Models.add(new CheckItemClass('Miscellaneous (Google Search Items)',obj.GIS_Stip_Notes_Miscellaneous_Search__c,obj.GIS_Stip_Miscellaneous_Search__c));
            return Models;



            So Models.add() is not really calling any method in the Models class, but the List.add() method. Also refer to the return statement which confirms as what you are returning.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 14 at 21:19

























            answered Dec 14 at 21:06









            Jayant Das

            12.1k2623




            12.1k2623











            • thank you! I realized I missed the List<CheckItemClass> Models = new List<CheckItemClass>();. This is a good example of how important naming is. It can get easily confusing!
              – Olivia
              Dec 14 at 21:11
















            • thank you! I realized I missed the List<CheckItemClass> Models = new List<CheckItemClass>();. This is a good example of how important naming is. It can get easily confusing!
              – Olivia
              Dec 14 at 21:11















            thank you! I realized I missed the List<CheckItemClass> Models = new List<CheckItemClass>();. This is a good example of how important naming is. It can get easily confusing!
            – Olivia
            Dec 14 at 21:11




            thank you! I realized I missed the List<CheckItemClass> Models = new List<CheckItemClass>();. This is a good example of how important naming is. It can get easily confusing!
            – Olivia
            Dec 14 at 21:11











            3














            Name shadowing can take many forms...



            Here is my personal favorite (as I have made this mistake more than once wrto name shadowing) from the lazy loading pattern...



            public Contact contacts 
            get
            if (contacts == null)
            Contact contacts = [SELECT ... FROM Contact WHERE ...]; //oops - declared new vbl!

            return contacts;
            private set;


            if (contacts.isEmpty()) ... . // null pointer exception!





            share|improve this answer

























              3














              Name shadowing can take many forms...



              Here is my personal favorite (as I have made this mistake more than once wrto name shadowing) from the lazy loading pattern...



              public Contact contacts 
              get
              if (contacts == null)
              Contact contacts = [SELECT ... FROM Contact WHERE ...]; //oops - declared new vbl!

              return contacts;
              private set;


              if (contacts.isEmpty()) ... . // null pointer exception!





              share|improve this answer























                3












                3








                3






                Name shadowing can take many forms...



                Here is my personal favorite (as I have made this mistake more than once wrto name shadowing) from the lazy loading pattern...



                public Contact contacts 
                get
                if (contacts == null)
                Contact contacts = [SELECT ... FROM Contact WHERE ...]; //oops - declared new vbl!

                return contacts;
                private set;


                if (contacts.isEmpty()) ... . // null pointer exception!





                share|improve this answer












                Name shadowing can take many forms...



                Here is my personal favorite (as I have made this mistake more than once wrto name shadowing) from the lazy loading pattern...



                public Contact contacts 
                get
                if (contacts == null)
                Contact contacts = [SELECT ... FROM Contact WHERE ...]; //oops - declared new vbl!

                return contacts;
                private set;


                if (contacts.isEmpty()) ... . // null pointer exception!






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 15 at 0:11









                cropredy

                35k439120




                35k439120



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Salesforce Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f242685%2fadding-a-wrapper-class-to-an-external-class%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?