Would you help me please~

I want to return the name of the account with the string parameter (Account's ID) handed over from JS!

I converted the id of the account to string in JS and handed it over to the apex class.

which is String accountIdList and it has data looks like a071s0000093T8hAAE, a071s0000093RDzAAM, a071s0000092WKRAA2

So i convert String accountIdList to List which is List<String> accountIdLists = accountIdList.split(',');

And i was supposed to turn for loop and add this ID to Set a = new Set(); I wanted to add it here, but it doesn't work!

I made Account list and wanted to return account1 and send the Id and Name of account back to JS!
List<Account> account1= [SELECT Id,Name FROM Account Where id in:a];

What should I do? Please help me, masters!

here is my hole code.

  public static List<Account> getChatterAccountName(String accountIdList) {

  List<String> accountIdLists = accountIdList.split(',');

  Set<Id> a = new Set<Id>();

  for(String s :accountIdLists){

  List<Account> account1= [SELECT Id,Name FROM Account Where id in:a];

  return account1;

1 Answer 1


This is unnecessarily complicated code, just pass in the list directly:

public static Account[] getChatterAccountName(Id[] accountIds) {
  return [SELECT Name FROM Account WHERE Id = :accountIds];

In your JavaScript, make sure you are passing in the values as an Array, and Apex will take care of the rest for you.

  • !! Thank you very much sir!! I made it~ your code is works!!
    – Yeonbi Ji
    Feb 7 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .