You need to sign in to do that
Don't have an account?
Deepika Gupta 26
How to associate contact on account Hierararchy
Hi,
I have a requirement to show hierarchy of accounts and its related account.I am able to show an account hierarachy on VF Page but i am not able to associate contacts to particular account.
Means ParentAccount->ChildAccount1->ChildContact1,ChildContact2->ChildAccount2->ChildContact1,ChildContact2.
Could any one know that how can i code to its related contacts on accounts.
I have a requirement to show hierarchy of accounts and its related account.I am able to show an account hierarachy on VF Page but i am not able to associate contacts to particular account.
Means ParentAccount->ChildAccount1->ChildContact1,ChildContact2->ChildAccount2->ChildContact1,ChildContact2.
public without sharing class HierarchyTree { public static String currentId {get; set;} private static Account currentAccount { get { if (currentAccount == null) { currentAccount = [select Name, ParentId, UltimateParent__c From Account where Id = :currentId]; } return currentAccount; } private set; } private static Account ultimateParentAccount { get { if (ultimateParentAccount == null) { if (currentAccount.UltimateParent__c != null) { ultimateParentAccount = [select Name, ParentId, UltimateParent__c from Account where Id = :currentAccount.UltimateParent__c]; } else { ultimateParentAccount = currentAccount; } } return ultimateParentAccount; } private set; } /** * @description This methos is used to generate JSON data for jsTree component */ public static String getJsonTree() { List<JSTreeNode> listItems = new List<JSTreeNode>(); listItems.add( new JSTreeNode( ultimateParentAccount.Id, '#', ultimateParentAccount.Name, new JSTreeNodeState(true, false, false), new JSTreeNodeAAttr(String.valueOf(ultimateParentAccount.Id) == currentId ? 'font-weight:bold' : '') ) ); for (Account acc : AccountHierarchyServices.getAllChildren(new List<Account>{ultimateParentAccount})) { listItems.add( new JSTreeNode( acc.Id, acc.ParentId, acc.Name, new JSTreeNodeState(true, false, false), new JSTreeNodeAAttr(String.valueOf(acc.Id) == currentId ? 'font-weight:bold' : '') ) ); } return JSON.serialize(listItems); } /** * This class is used to generate jsTree node */ @TestVisible private class JSTreeNode { public String id; //required public String parent; //required public String text; // node text public String icon; // string for custom icon public JSTreeNodeState state; // instance of JSTreeNodeState public Object li_attr; // attributes for the generated LI node public JSTreeNodeAAttr a_attr; // attributes for the generated A node public JSTreeNode(String id, String parent, String text, JSTreeNodeState state, JSTreeNodeAAttr a_attr) { this.id = id; this.parent = parent; this.text = text; this.state = state; this.a_attr = a_attr; } } @TestVisible private class JSTreeNodeState { public Boolean opened; // is the node open public Boolean disabled; // is the node disabled public Boolean selected; // is the node selected public JSTreeNodeState(Boolean opened, Boolean disabled, Boolean selected) { this.opened = opened; this.disabled = disabled; this.selected = selected; } } @TestVisible private class JSTreeNodeAAttr { public String style; // style of current node public JSTreeNodeAAttr(String style) { this.style = style; } } }
Could any one know that how can i code to its related contacts on accounts.
Please check the below code to retrieve the list of contacts associated to the given Account.
Regards,
Mahesh
But i am aware of the query since i am new to the development and not familar with the syntax dont where i can assoicate this query to get required result.awaiting for your reply.thanks