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

    How a Dedicated Salesforce Lightning Developer Can Upgrade Your CRM

    How a Dedicated Salesforce Lightning Developer Can Upgrade Your CRM

    Blog in Salesforce

    Welcome to the future of customer relationship management!  In today's fast-paced digital world, staying ahead of the curve is not just a choice but a…

    Business, choose, Cloud-based Solution, CRM, Custom Applications
    eShopSync Nov 8, 2023
    1,973  Views
    Salesforce Artificial Intelligence for Sales Cloud to Increase Productivity and Growth

    Salesforce Artificial Intelligence for Sales Cloud to Increase Productivity and Growth

    Blog in Others

    Salesforce AI for Sales Cloud, as well as additional capabilities like an embedded assistant copilot for Sales, allow every sales professional, leader, and operations team…

    Cloudmetic Dec 15, 2023
    1,162  Views

    What is the Future Scope of Salesforce CRM?

    Blog in Salesforce

    Nowadays the adoption of Salesforce CRM is increasing at a tremendous pace. As per reports, Salesforce dominated the worldwide CRM market with a market share…

    AppExchange, Build Applications, Business Relationships, cloud marketplace, Consultants
    DianApps Dec 8, 2022
    2,687  Views

    Popular Salesforce Videos

    TrailheaDX '18 Opening Keynote - Part 5: Make Apps Smarter

    TrailheaDX '18 Opening Keynote - Part 5: Make Apps Smarter

    Video in Trailhead

    Related Videos: Salesforce TrailheaDX ’18 Opening Keynote – Part 1: Create Connected Customer Experiences TrailheaDX ’18 Opening Keynote – Part 2: Salesforce Platform TrailheaDX ’18…

    Salesforce Einstein, Salesforce Trailhead, Salesforce Dashboards, Customer Success, Salesforce Keynote
    Abhay Apr 3, 2018
    2,165  Views
    What is Billing - Salesforce Revenue Cloud

    What is Billing - Salesforce Revenue Cloud

    Video in Salesforce Cloud Platform

    How can you transform your billing system for subscription and usage models? By dropping your legacy systems and streamlining your processes. In this video, learn…

    Salesforce Training, Salesforce Video, Customers, Salesforce Learning, Subscription
    Jogender Jan 27, 2021
    2,434  Views
    What is Salesforce? Why Salesforce? Salary Expectation | Certification Required

    What is Salesforce? Why Salesforce? Salary Expectation | Certification Required

    Video in Salesforce Certifications

    Watch this video and learn all about Salesforce and how to make a career in Salesforce. What is Salesforce? Why Salesforce? Salary Expectation | Certification…

    Salesforce Training, Salesforce Tutorial, Salesforce Certification, salesforce, Salesforce Video
    Rupal Kakkar Nov 30, 2021
    2,081  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.