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, 10 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

    Meet Resco at Dreamforce

    Salesforce Mobility & Security – When the user’s PIN is simply not enough

    Blog in Salesforce Security

    Many of us love and prefer using Salesforce and working with Salesforce data in remote locations, on mobile devices. With an ever-increasing popularity and high-speed…

    Business Mobility, Field Service, Offline CRM, Resco, SALES
    Barbora Jun 29, 2018
    5,048  Views
    Unravel the Advantages of Salesforce Marketing Cloud

    Unravel the Advantages of Salesforce Marketing Cloud

    Blog in Salesforce Products

    Salesforce has continued to be a market leader in offering Customer Relationship Management (CRM). Presently, it holds over 19.5% share of the market, defeating all…

    Automation, Behaviors, Building Customer Relationships, Campaign Management, Campaign Performance
    Melonleaf Apr 11, 2023
    1,777  Views
    Debugging Salesforce orgs

    Troubleshooting and Debugging Salesforce orgs in The Welkin Suite

    Blog in Coding and Scripting

    Even though Salesforce has always been an innovative platform, just a couple years ago our troubleshooting options seemed as they were much more closer to…

    Cloud Computing, Salesforce, Salesforce Community, Salesforce Developers, Salesforce Development
    The Welkin Suite Jul 3, 2017
    5,601  Views

    Popular Salesforce Videos

    What is Lookup Relationship in Salesforce?

    What is Lookup Relationship in Salesforce?

    Video in Salesforce Stories, Salesforce Training

    In this video, Shrey is not only teaching but also demonstrating to you "What is Lookup Relationship in Salesforce?". You will be learning: 1. How…

    Salesforce Training, Salesforce Administrator, Lookup Relationship In Salesforce, Salesforce Learning, Journey with Salesforce
    Jogender Sep 10, 2020
    1,875  Views
    Integrate Salesforce with Amazon S3

    Integrate Salesforce with Amazon S3

    Video in Salesforce Integration

    Dear #Trailblazers, In this video, we are going to learn how to connect #Salesforce with #Amazon S3. We are going to use Named Credentials which…

    Salesforce Training, Salesforce Integration, salesforce, Salesforce Video, Salesforce Learning
    Jogender May 27, 2020
    1,838  Views
    How to Send a Pardot Email with Multiple Line Items | Salesforce

    How to Send a Pardot Email with Multiple Line Items | Salesforce

    Video in Salesforce Products

    It is impossible to send a Pardot email that has a list of related records… or is it? In this session, Adam Erstelle uncovers strategies…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Abhishek Nov 30, 2021
    1,680  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.