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
Apex developer 21Apex developer 21 

Constructor not defined: [HierarchyNode].<Constructor>(Account, HierarchyNode)

I get the following error in my class: Constructor not defined: [HierarchyNode].<Constructor>(Account, HierarchyNode) .

The code looks like:
public class Nodeshierachy {

// Add child nodes
private static void addChildren(List<Account> accs, Map<Id,HierarchyNode> nodes, Set<Id> parent_acc_ids) {
    for (Account acc : accs) {
        HierarchyNode ref_node = nodes.get(acc.ParentId);
        HierarchyNode new_node = new HierarchyNode(acc, ref_node);
        nodes.put(acc.id, new_node);
        if (ref_node != null) {
            ref_node.children.add(new_node);
        }
        if (parent_acc_ids != null) {
            parent_acc_ids.add(acc.id);
        }
    }
}
Amit Singh 1Amit Singh 1
Hello,

You are getting the error because of the following line:
HierarchyNode new_node = new HierarchyNode(acc, ref_node);
You need to define a constructor in "HierarchyNode" class. Define the constructor like below:
public void HierarchyNode(Account acc, HierarchyNode Node)
Or need to change your code as per your requirement.

Let me know if this helps :)

Thanks,
Amit Singh