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, 4 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 AI-Powered Salesforce Workflows Are Changing Enterprise Operations

    How AI-Powered Salesforce Workflows Are Changing Enterprise Operations

    Blog in Salesforce

    An AI-powered Salesforce workflow is a business process where AI agents read CRM and enterprise data, reason about a request, act through Flows, Apex, and…

    Shivam Oct 7, 2026
    143  Views
    7 Signs Your Company Needs a Salesforce Consulting Partner

    7 Signs Your Company Needs a Salesforce Consulting Partner

    Blog in Salesforce Consultant

    1. Struggling with Salesforce Adoption One of the most common challenges businesses face is low adoption rates of Salesforce among their teams. Despite its powerful…

    api-integration, Business Objectives, Change Management, Customer Engagement, Customer Satisfaction
    Infodriven Jun 4, 2024
    772  Views

    Top 4 Considerations in Choosing your Salesforce CPQ Partner

    Blog in Salesforce Products

    Congratulations, you’ve made the decision to implement Salesforce CPQ! Now comes the challenging task of choosing the right Salesforce CPQ partner to help fulfill your…

    Sales Management, Salesforce Consulting Partner, Salesforce CPQ benefits, Salesforce CPQ Implementation, Salesforce CPQ Partner
    LevelShift (formerly DemandBlue) Aug 5, 2019
    2,612  Views

    Popular Salesforce Videos

    CPQ B2B Commerce Cloud Connector | Salesforce Tutorial

    CPQ B2B Commerce Cloud Connector | Salesforce Tutorial

    Video in Salesforce Products, Salesforce Training

    In these difficult economic times, businesses are looking for ways to improve efficiency and reduce the cost of doing business. More than ever, efficiency and…

    Salesforce Training, Salesforce Tutorial, salesforce, CPQ, Salesforce Video
    Algoworks Nov 16, 2021
    2,894  Views
    What Does a Salesforce Developer Do | Salesforce Developer Roles and Responsibilities

    What Does a Salesforce Developer Do | Salesforce Developer Roles and Responsibilities

    Video in Salesforce Training

    Watch this video to learn all about Salesforce Developer Roles and Responsibilities. This video explains what does a Salesforce Developer do. Watch and learn.

    Salesforce Training, Salesforce Tutorial, Salesforce Developer, salesforce, Salesforce Video
    Nauman Oct 11, 2021
    1,815  Views
    Dreamforce 2021 Main Keynote - Welcome to the Trusted Enterprise | Salesforce

    Dreamforce 2021 Main Keynote - Welcome to the Trusted Enterprise | Salesforce

    Video in Salesforce Stories

    Today, every business has to transform to become a Trusted Enterprise. Join Marc Benioff & special guests to learn how Customer 360 helps businesses of…

    Salesforce Training, Salesforce Tutorial, dreamforce, salesforce, salesforce knowledge
    Nauman Oct 5, 2021
    2,701  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.