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
Firas Taamallah 18Firas Taamallah 18 

How to find Top account in accountHierarchy based on Contact's Account and the new Account which will be inserted in AccountContactRelation using Apex ??

Hello ,

My goal is when i try to add account throught Add Relationship button in Contact related list , the new account should be part of the Account Hierarchy of the contact's account , if not error message will be displayed

To do this , i need to compare :
  1.  Top account of the contact's account in Account Hierarchy
  2.  Top Account of the new account you are trying to add throughout Add Relationship button
  3.  if top accounts are the same so it means the new account is part of Account Hierarchy of Contact's Account , so in this case i would be able to insert it

How can i achieve this?
Thanks