Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8211971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:36:29+00:00 2026-06-07T10:36:29+00:00

Hello Folks, I have a list which has values from a query. The list

  • 0

Hello Folks,
I have a list which has values from a query. The list has multiple fields, how can I access a specific field from this list?

Problem:

List <Account> listS = [Select 
                         (Select S__c from AS__r 
                         where S__r.Abc__c = 'Confirmed'), 
                         (Select PQR__c from AHS__r) 
                       from Account where Id in: TravellerIds];

List <AS__c> listAS = new list <AS__c>();
for (Account t: listS){
    listAS.add(t.AS__r);
}

Problem in pseudocode:
For (every Account in listS)
{
ListAS.add(S__c field from the listS);
}

I have tried what I mentioned in the Problem section but I am unable to access it. Please help me.

Error that I get is this : List has more than 1 row for assignment to SObject.

Thanks a lot for the help.

Note: I do not want to access the S_c field inside the for loop for every AS_c.. I want to access it for every Account.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:36:31+00:00Added an answer on June 7, 2026 at 10:36 am

    As you’re querying a parent child relationship the field t.AS__r on the Account object is actually a list of the objects that meet the sub query criteria. Therefore all you need to do is change listAS.add(t.AS__r); to be listAS.addAll(t.AS__r); and this will make your example code work – adding all of the items returned in the sub query to your new list.

    By extension if you wanted to add all the S_c fields, as you say in your pseudo code, then all you need to do is loop through the sub query list for each account and add the S_c field to a list like so:

    List<string> listOfS = new List<string>();
    for(Account acc : listAS){
      for(A__c a: acc.AS__r){
         listOfS.add(a.S__c);
      }
    }
    

    This presumes that your custom object referred to by the relationship name AS__r has an API name of A__c and that the field S__c is of type string – but hopefully you get the idea.

    Does this help?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code can be found here: http://www.myhorizon.ca/client_central/sortable_test.php Hello folks of Stackoverflow, I have a list
Hello I have a table on which I have denied SELECT privs to a
Hello folks :) I have a quick question - For the following NSMutableArray: NSMutableArray
Hello I have a double linked list set up, and i have a search
Hello good morning everyone, i have an iphone app which is still in development
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello folkes I have this little problem for which I cannot find a suitable
Hello folks, I've got the issue to add a browser event to some input
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
Hello! I would like to extract all citations from a text. Additionally, the name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.