function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nicholas WillardNicholas Willard 

Illegal assignment from LIST<Account> to String

I'm getting an error "Illegal assignment from LIST<Account> to String" when I go to execute my code in the Execute Anonymous Window.  Any help would be greatly appreciated.

Here is what my code looks like so far:

public with sharing class TopDown {
    
    public void SortAccounts(){
    
        List<String>relAccounts = new List<String>(); //Empty list of accounts of a given Relationship Manager
        String relManName = 'J%';
    
        //Loop through all the accounts for a specified Relationship Manager
        
        for (Account acct:[SELECT Account__c FROM Relationship_Manager_Accounts__c WHERE Relationship_Manager_Contact__r.name like :relManName]){
        //Get the child id for the given account id
        
            String childId = [SELECT id FROM Account WHERE parent.id =:acct.id];
            //While there still is a child
        
            while(childId != null){
                childId = [SELECT id FROM Account WHERE parent.id = :childId];
                relAccounts.add(childId);
            }
        }
    }
    
}
Nicholas KinzelNicholas Kinzel
String childId = [SELECT id FROM Account WHERE parent.id =:acct.id];

This returns a list of Accounts, which cannot be assigned to a string.
Nicholas WillardNicholas Willard
Thanks for the response.  I'm going to take a different approach.