• Nicholas Kinzel
  • NEWBIE
  • 5 Points
  • Member since 2014
  • .Net Developer
  • Emerson

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    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);
            }
        }
    }
    
}