You need to sign in to do that
Don't have an account?

Doubt regarding collection List
Hi,
i am new to salesforce.
i have doubt on collection list
1. I need to retrieve records from an object(Ex: Account)
2. Then I have to add those records to collection LIST dynamically one by one
i have use below code But it's giving error So i don't know how to achive it
list<string> s = new list<string>();
for (Account tmp : [SELECT name FROM Account order by name])
{
s.add(tmp);// to add records to list
system.debug(tmp);
}
Hi ,
Try this
List<Account> listAccount = new list<Account>();
for (Account tmp : [SELECT name FROM Account order by name])
{
listAccount.add(tmp.name);// to add records to list
system.debug(tmp);
}
If the above ans helps you, mark it as resolved.
Cheers
Sanj
The list declaration should be of type string only, if you wanted to add Account's Name, if you want to add the whole record then it should be List<Account>
--yvk
just try this,
List<Account> Acc=new List<Account>();
Acc=[SELECT name FROM Account order by name];
Now "Acc" will have the complete list of accounts.
Thanks,
Praveen K.