You need to sign in to do that
Don't have an account?
Apex 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);
}
}
}
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);
}
}
}
You are getting the error because of the following line: You need to define a constructor in "HierarchyNode" class. Define the constructor like below: Or need to change your code as per your requirement.
Let me know if this helps :)
Thanks,
Amit Singh