Toggle Side Panel

  • Blogs
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Blogs
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › Fetch account details using "AccountContactRelation" junction object in Salesforce

    Tagged: Account Detail, AccountContactRelation, Junction Object, Salesforce Objects, Salesforce Org

    • Salesforce® Discussions

      Fetch account details using "AccountContactRelation" junction object in Salesforce

      Posted by Martina on November 20, 2017 at 7:52 PM

      Hi,

      I am stuck with a problem here.

      I have enabled multiple Accounts to Contact in my Salesforce org. This creates a junction object called AccountContactRelation.

      I need to write a query which would fetch the account details like Account id, name, record type of the Accounts linked to a Contact.

      Condition is, only those account details should be fetched where the contact has more than one account linked to it.

      Can someone please help. It is urgent

      Thanks!

      Ajay Prakash replied 8 years, 9 months ago 2 Members · 1 Reply
      • Account Detail
      • AccountContactRelation
      • Junction Object
      • Salesforce Objects
      • Salesforce Org
    • 1 Reply
    • Ajay Prakash

      Member
      January 4, 2018 at 5:37 AM

      Hi Martina,

      It will be a two-step process. First, you need to fetch all contact ids which has more than one contact.In the second step, you can retrieve Account information.

      set<Id> setOfContactIds = new set<id>();
      for(Contact conObj : [select id, (select id from AccountContactRelations where isDirect = false) from contact]){
      if(conObj.AccountContactRelations.size()>0){
      setOfContactIds.add(conObj.id);
      }
      }
      system.debug('::'+[select id, Account.name from AccountContactRelation where ContactId IN:setOfContactIds]);

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    Popular Salesforce Blogs

    Salesforce CRM, NetSuite ERP Integration: Benefits, Guide, Best Practices

    Blog in Salesforce integration

    NetSuite is the #1 Cloud ERP. In 2022, NetSuite became a leader in the Gartner Magic Quadrant for Cloud ERP for Service-Centric Enterprise. As you…

    Automated Workflows, Business Growth, Business Scalability, Celigo Connector, Client Onboarding
    Sparkybit Nov 17, 2023
    2,767  Views
    Salesforce Lightning Ready Toggle

    Salesforce Lightning Ready Toggle

    Blog in Lightning, Salesforce customization, Salesforce Implementation

    Nowadays most of the salesforce projects are shifted to Lightning Ready and jQuery acts as a very good tool while designing Lightning Ready Pages. In…

    jQuery, Lightning Design System, Lightning Ready, Lightning Ready Pages, Lightning Ready Toggle
    Manpreet Jan 18, 2018
    11,343  Views

    Salesforce & SharePoint Integration – A Combination To Enhance Business Processes

    Blog in Salesforce integration

    Salesforce SharePoint Integration – Salesforce is the world’s #1 cloud-based CRM giant offering comprehensive CRM solutions to millions of leading brands across the globe. However,…

    Chatter, CRM Solutions, Salesforce Chatter, Salesforce Integration, Salesforce Sharepoint integration
    LevelShift (formerly DemandBlue) Aug 22, 2019
    4,162  Views

    Popular Salesforce Videos

    How to Configure SAML Single Sign-On with Salesforce as the Identity Provider

    How to Configure SAML Single Sign-On with Salesforce as the Identity Provider

    Video in Salesforce Training

    Configure single sign-on with a Salesforce org as the identity provider for an external Heroku app acting as the service provider, using SAML. Watch this…

    salesforce, Salesforce Org, Salesforce Video, Salesforce leaarning, Configure SAML
    Prafull Aug 11, 2020
    1,553  Views

    Real Time Synchronization between Salesforce and Quickbooks | eShopSync for Quickbooks

    Video in Salesforce Integration

    Now you can easily sync your data between Quickbooks and Salesforce  through Real-Time Synchronization Feature, which allows you to import data from Salesforce to Quickbooks.…

    Salesforce Training, Salesforce Integration, salesforce, Salesforce Video, Salesforce Learning
    Deepika Jul 13, 2020
    1,773  Views
    Lightning Component In Salesforce

    Lightning Component In Salesforce

    Video in Lightning, Salesforce Development

    In this video, we are going to look into: Lightning Component Lightning Component features Types of Lightning Component Lightning Component bundle Watch this video and…

    Salesforce Developer, Salesforce Lightning, salesforce, Salesforce Admin, Lightning Component Bundle
    kanika May 12, 2021
    1,827  Views
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.