Search code examples
salesforceapex-codeapex

Reference of returned object?


If I have a class as follows:

class MyClass
{
   List<String> list{get;set;} 
...
}

And then execute:

MyClass instance = new MyClass();
instance.add('string') ;

Will that new entry in the list be added to the member variable instance?


Solution

  • No. What you trying to do should be more like

     class MyClass{
        public List<String> list{get;set;} 
     }
    

    and then execute

     MyClass instance = new MyClass();
     instance.list.add('string');