+ 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) {
        if (parent_acc_ids != null) {
Amit Singh 1Amit Singh 1

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 :)

Amit Singh