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 › What is the SOQL query to get all accounts related to a contact?

    Tagged: Contacts Data, Multiple Account Relationship, Rollup, Salesforce Account, SOQL Query

    • Salesforce® Discussions

      What is the SOQL query to get all accounts related to a contact?

      Posted by Delano on August 17, 2018 at 5:36 PM

      I need to roll-up to contacts data from related accounts. As a first step, how would the query look like to get for example the number of accounts related to a contact, or better, total AnnualRevenue of all related accounts?

      David Levi replied 3 years, 2 months ago 3 Members · 3 Replies
      • Contacts Data
      • Multiple Account Relationship
      • Rollup
      • Salesforce Account
      • SOQL Query
    • 3 Replies
    • Avnish Yadav

      Member
      August 20, 2018 at 6:52 AM

      Hi Delango.

      Here is sample code:-

      List<Account> acc=[Select Id,Name from Account];
      for(Account a:acc){
      List<Contact> con=[Select accountId, LastName from contact where AccountId=:a.id];

      Integer TotalAnnualRevenue = 0;
      for(Contact c:con){
      TotalAnnualRevenue = TotalAnnualRevenue+c.AnnualRevenue
      System.debug('Total revenue'+ TotalAnnualRevenue);
      }

      }

      Hope this will help you.

      Thanks.

    • [adinserter block='9']
    • Delano

      Member
      August 22, 2018 at 10:09 PM

      I should have clarified that I have enable the Contact to multiple Accounts relationship and what I'm trying to solve for is to roll-up data to the contact from all related accounts.

    • David Levi

      Member
      June 26, 2023 at 1:39 PM

      You do a SOQL query in LOOP - Its the best practice to fail on Governor Limits

    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

    Dreamforce 2022 Highlights

    Dreamforce 2022 Highlights - Everything You Need To Know

    Blog in Salesforce, Salesforce Products

    The Salesforce’s annual event, “Dreamforce” was held in San Francisco from September 21 to 23, completing their 20 years of magnificence. This year’s event was…

    AWS, Azure, Business, Business Journeys, Carbon Credits
    Melonleaf Oct 14, 2022
    2,587  Views

    Case Study: Empowering Global Pharma Customer Support

    Blog in Salesforce

    Transformative impact of the Salesforce Service Cloud Call Center Solution on enhancing customer support across multiple countries within the pharmaceutical industry. The pharmaceutical industry operates…

    Business Process Transformation, Call Center Solution, Call Control Application, Case Management, Case Routing
    Triple Innovations Oct 5, 2023
    1,578  Views
    Zero-Downtime Commerce Migration Moving from Legacy E-Commerce to Salesforce Commerce Cloud

    Zero-Downtime Commerce Migration: Moving from Legacy E-Commerce to Salesforce Commerce Cloud

    Blog in Salesforce

    Every hour of downtime on a retail site drains money. Industry research pegs enterprise downtime costs at $1 million or more per hour, and some…

    Salesforce Commerce, Salesforce Commerce Cloud
    James Jul 8, 2026
    611  Views

    Popular Salesforce Videos

    Salesforce Essentials vs Professional

    Salesforce Essentials vs Professional

    Video in Salesforce Implementation, Salesforce Training

    In this video, Bradley Large answers some of the most common questions people have about Salesforce. He gives clear and concise answers to questions like:…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Editions
    Rahul kapoor Nov 21, 2022
    2,242  Views
    Marc Benioff talks Salesforce - AT&T deal, office health safety and online media regulation

    Marc Benioff talks Salesforce - AT&T deal, office health safety and online media regulation

    Video in Salesforce Stories

    Salesforce’s Customer 360 will enable AT&T to deliver highly-tailored customer experiences seamlessly across retail, marketing, online, business, and more. AT&T will utilize Salesforce’s entire portfolio…

    salesforce, Salesforce Einstein, Salesforce Video, Sales Cloud, Tableau
    Pooja May 29, 2020
    2,275  Views
    Apex Design Patterns : The Singleton Pattern in Salesforce || #Salesforce #DesignPatterns

    Apex Design Patterns : The Singleton Pattern in Salesforce || #Salesforce #DesignPatterns

    Video in Salesforce Development

    The Singleton Pattern One Private variable of the class itself will hold the instance of the complete class so that we can access all the…

    salesforce, CRM, Apex, Training, Tutorial
    SFDC Sep 5, 2025
    369  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.