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
Matt McFedriesMatt McFedries 

Related Contacts with AccountContactRelation not showing in the Account page

Hi,

We have set up the AccountContactRelation to allow contacts to be related to multiple accounts. 

For some of the accounts the contacts are not showing in the contacts related list, but in the Contact page
the related account does appear on the accounts related list.

Checking through the API the relationship appears to be perfectly created too.

Can someone guide us through ?

Cheers.
samyuktha etikyalasamyuktha etikyala
Hi Dear,

Hope below code will help you,

<apex:repeat value="{!accounts}" var="accWrap">
 <apex:outputText value="User ID : {!accWrap.userId}"/>
 <apex:repeat value="{!accWrap.accounts}" var="acc">
    <apex:outputText value="Account : {!acc.Name}"/> 
     <apex:repeat value="{!acc.contacts}" var="cont">
       <apex:outputText value="Contact : {!cont.Name}"/>
   </apex:repeat>

   </apex:repeat>

</apex:repeat>

Controller:

public class accountcontact
{
   list<AccountWrapper> wraplist=new list<AccountWrapper>();
   public accountcontact()
    {
      Map<Id, AccountWrapper> accMap=new Map<Id, AccountWrapper>();
      for(account a:[SELECT CreatedbyID,Account.Name,(SELECT     
              name,Contact.FirstName, Contact.LastName
              FROM Account.Contacts) FROM Account])
     {         
 AccountWrapper accWrap=accMap.get(a.CreatedByID);
          if (null==accWrap)
         {
             accWrap=new AccountWrapper();
            accMap.put(a.CreatedByID, accWrap);
             accWrap.userId=a.CreatedById;
         }

         accWrap.accounts.add(a);
      }

       wrapList=accMap.values();
   }

  public list<AccountWrapper> getaccounts()
   {
     return acclist;
  }
 
  public class AccountWrapper
  {
     public Id userId {get; set;}
      public List<Account> accounts {get; set;}
      public AccountWrapper()
     {
         accounts=new List<Account>();
      }
  }
}