+ Start a Discussion
Siddhant Singh 5Siddhant Singh 5 

how to retrive list of account names from list of account id

Raj VakatiRaj Vakati
from Set Of Ids

Set<Id> accs =new Set<Id.>();
accs.add('001xxxxxxxxxxx');
accs.add('001xxxxxxxxxxx');


List<Account> acclist = [Select Id from Account where Id in :accs ]; 

from List Of Ids

List<Id> accsLst =new List<Id.>();
accs.add('001xxxxxxxxxxx');
accs.add('001xxxxxxxxxxx');

Set<Id> idsSet = new Set<Id>();
idsSet.addAll(accsLst );
List<Account> acclist = [Select Id from Account where Id in :idsSet]; 
HARSHIL U PARIKHHARSHIL U PARIKH
Let's say you have a list of account Id as this: 
List<Id> actIds; // actIds are filled with account ids.
You can do something like this to retrive account records 
List<Account> acts = [SELECT Id, Name FROM Account WHERE Id =: actIds];

and then, you can retrieve the name in an another list like below,
 
List<String> accountNames = New List<String>();
For(Account EveryAccount : acts){
   accountNames.add(EveryAccount.Name);
}
Hope this helps!


 
Umesh RathiUmesh Rathi
Let's say you have List of Account Id as lstAccountID
Simply write a SOQL query to fetch the account using these IDs.
List<Account> lstAcount = [Select, id,name from Account where id =: lstAccountID];
for(Account acc : lstAcount ){
System.debug(acc.name);
}

Thanks! :)
Hans PeterHans Peter
Thanks :)
Ankit SatnalikaAnkit Satnalika
List<Account> accID = [select id from Account limit 10];
List<Account> accName = [select name from Account where id = :accID];
system.debug(accName);

Hope this helps