+ Start a Discussion
chikka vamshi 10chikka vamshi 10 

Create a list collection example using sObject account

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Vamshi,

Are you looking for how do we collect the Account as list. If so you can use the below.
 
List<Account> acclist=[Select id, Name from Account];

If not please provide more details for the question.

If this answer helps you, Please mark it as best answer.

Thanks,


 
ravi soniravi soni
hi chikka,
list<Account> lstAccount = new list<Account>();

for(integer i=0; i<10; i++){
Account acc = new Account();
acc.Name = 'Account ' + i;
lstAccount.add(acc);
}
if(lstAccount.size() > 0){
insert lstAccount;
}
here is dummy example of creating list in bulk. try this, I believe it will help you.
don't forget to mark it as best answer.
thank you

 
CharuDuttCharuDutt
Hii Chikka
Try Below Code
list<Account> lstAccount = new list<Account>();

for(integer i=0; i<10; i++){
Account acc = new Account();
acc.Name = 'Account ' + i;
lstAccount.add(acc);
}
if(lstAccount.size() > 0){
insert lstAccount;
}

###########################
list<Account> NewlstAccount = new list<Account>();
List<Account> lstAccount = [Select id, Name,Amount from Account];



for(Account Acc : lstAccount){
if(Acc.Amount != null){
NewlstAccount.add(Acc);
}
}
sytem.Debug(NewlstAccount.size());
sytem.Debug(lstAccount.size());
Please Mark It As Best Answer If It Helps
Thank You!
ravi soniravi soni
hi chikka,
did you try any solution. please close your query by marking as best answer whatever answer was best for you. 
Thank you