public Class FetchAccount{
public static void fetchName(){
try{
List<Account> account1= [SELECT Id,Name FROM Account];
Set<Id> accountIdSet=new Set<Id>();
for(Account acc:account1){
accountIdSet.add(acc.Id);
}
List<Account> accName =[SELECT Name FROM Account where Id In:accountIdSet];
for(Account ac:accName){
system.debug(ac.Name);
}
}catch(Exception e){
System.debug('Exception due to-->: '+e.getMessage());
}
}
}
If you find your Solution then mark this as the best answer.
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];
and then, you can retrieve the name in an another list like below,
Hope this helps!
Simply write a SOQL query to fetch the account using these IDs.
Thanks! :)
List<Account> accName = [select name from Account where id = :accID];
system.debug(accName);
Hope this helps
"Try this code."
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi