• Nicholas Willard
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
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);
            }
        }
    }
    
}
I would like to know the best way to query a hierarchical database to find parent, grandparent, great-grandparent... I think I need to use a combination of Apex and SOQL.  Once I'm at the top I need to find out who the Manager is for all the children.  I am trying everything I can think of to not have query governor issues. Any help would be greatly appreciated.
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);
            }
        }
    }
    
}
I would like to know the best way to query a hierarchical database to find parent, grandparent, great-grandparent... I think I need to use a combination of Apex and SOQL.  Once I'm at the top I need to find out who the Manager is for all the children.  I am trying everything I can think of to not have query governor issues. Any help would be greatly appreciated.