Skip to main content
added 60 characters in body
Source Link
Adamo
  • 381
  • 6
  • 22

This should work:

List<String> lstNames = new List<String>();
for(A__c ac: [Select Name from A__c where field__c =: objB.Id]){
    lstNames.add(ac.Name);
}
String names = string.join(lstNames,',');
System.debug(names);

Your code not works because you are trying to assign an object to a string.

-edit In my opinion, this is not possible without loop.

This should work:

List<String> lstNames = new List<String>();
for(A__c ac: [Select Name from A__c where field__c =: objB.Id]){
    lstNames.add(ac.Name);
}
String names = string.join(lstNames,',');
System.debug(names);

Your code not works because you are trying to assign an object to a string.

This should work:

List<String> lstNames = new List<String>();
for(A__c ac: [Select Name from A__c where field__c =: objB.Id]){
    lstNames.add(ac.Name);
}
String names = string.join(lstNames,',');
System.debug(names);

Your code not works because you are trying to assign an object to a string.

-edit In my opinion, this is not possible without loop.

Source Link
Adamo
  • 381
  • 6
  • 22

This should work:

List<String> lstNames = new List<String>();
for(A__c ac: [Select Name from A__c where field__c =: objB.Id]){
    lstNames.add(ac.Name);
}
String names = string.join(lstNames,',');
System.debug(names);

Your code not works because you are trying to assign an object to a string.