function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Siri Reddy 5Siri Reddy 5 

Instantiation

Hi,

Please help me know the difference between the below two :-

List<Account> accntList = new List<Account>();  ----   I'm creating an Instance.
List<account> accntList; ----   I'm just declaring a list variable.

Thanks and regards
Siri
Best Answer chosen by Siri Reddy 5
Rounak SharmaRounak Sharma
hi siri reddy,
the direct answer is
in the 1st case you are creating an instance of the object which will store the values of account object and you can refer the fields with the help of the instance but the 2nd case is just declaring list<Account> which will store the value of account type. you can not take the reference of the field .

Please let me know if it justifies your issue and mark it as a best answer
thanks

All Answers

Rounak SharmaRounak Sharma
hi siri reddy,
the direct answer is
in the 1st case you are creating an instance of the object which will store the values of account object and you can refer the fields with the help of the instance but the 2nd case is just declaring list<Account> which will store the value of account type. you can not take the reference of the field .

Please let me know if it justifies your issue and mark it as a best answer
thanks
This was selected as the best answer
Siri Reddy 5Siri Reddy 5
Thankyou Rounak