Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • 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
  • Marketplace
  • Advertise With Us
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • 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
    • Marketplace
    • Advertise With Us
    • 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 2 years, 5 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.

    • 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

    application solution

    Popular Salesforce Blogs

    How Salesforce Consulting Powers Business Growth

    Blog in Salesforce

    Have you ever wondered why, despite using the same tools and technology, some businesses seem to grow with ease while others struggle? The difference lies…

    Salesforce, Salesforce Consultant, Salesforce Consultants, Salesforce Consulting
    SP Nov 24, 2025
    122  Views
    Salesforce Business Process

    Salesforce Business Processes - Learn Here!

    Blog in Salesforce

    Salesforce is a leading customer relationship management (CRM) platform that helps businesses streamline and automate various processes. With its wide range of tools and features,…

    Automation, Business Processes, Collaboration, Collaboration and Communication, Communication
    SELCUK Dec 16, 2022
    1,638  Views
    Objects in Salesforce

    What Are Setup and Non-Setup Objects in Salesforce

    Blog in Others, Salesforce

    In this top salesforce blog, we will be discussing what are Setup and Non Setup Objects in Salesforce.  Setup and Non-Setup Objects in Salesforce Non-Setup…

    Builder Area, Business Purpose, Case, Coders, Contact
    Anjali May 20, 2021
    15,250  Views

    Popular Salesforce Videos

    How To Drive More Sales With Marketing Automation in 2023 | Marketing Cloud | Webinar

    How To Drive More Sales With Marketing Automation in 2023 | Marketing Cloud | Webinar

    Video in Salesforce Automation

    Are you curious about how to drive more sales for your business? Every business wants to create a market space for its business or product.…

    Salesforce Training, Salesforce Tutorial, salesforce, Marketing Automation, Salesforce Marketing Cloud
    Cyntexa Jan 3, 2023
    1,377  Views
    4 Benefits of Salesforce Vlocity Communications Clouds

    4 Benefits of Salesforce Vlocity Communications Clouds

    Video in Salesforce Cloud Platform, Salesforce Training

    Vlocity Communications effortlessly collaborate with Salesforce Service Cloud to design a solution to garner personalized and uninterrupted experience for customers throughout their channels. This not…

    Salesforce Training, Salesforce Service Cloud, salesforce, Salesforce Video, Customers
    Cyntexa May 9, 2022
    2,591  Views
    Salesforce Winter '23 Release Highlights - Video

    Salesforce Winter '23 Release Highlights - Video

    Video in Salesforce Products

    Cosy up by the fireplace with a nice blanket and a cup of hot cocoa; Salesforce's Winter '23 update is as cool as ice! With…

    Salesforce Training, Salesforce Tutorial, Salesforce Development, Salesforce Sales Cloud, Salesforce Service Cloud
    DB Sep 7, 2022
    1,789  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

    © 2025 - 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®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.