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

    Top Considerations in Choosing the Right Salesforce Development Partner

    Blog in Salesforce Consultant

    Salesforce is the world’s leading and one of the most powerful CRM platforms that can redefine your digital journey, foster stronger brand loyalty and engagement,…

    Salesforce Consulting, Salesforce Consulting Partner, Salesforce Development Company, salesforce Development Partner, Salesforce Development Services
    LevelShift (formerly DemandBlue) May 24, 2019
    3,054  Views
    salesforce communities

    Successful Implementation Of Salesforce Communities

    Blog in Salesforce Certifications

    Salesforce Communities has changed the way businesses can handle connections with their customers, partners, and employees. The communities relevant to the industry can be created…

    Businesses, Chatter Tab, Communities License, Customer Connections, Customers
    Arpit Jul 31, 2020
    3,157  Views

    Connecting to Salesforce with Devart Data Connectivity: A Comprehensive Overview

    Blog in Salesforce integration

    Salesforce is a cloud-based customer relationship management (CRM) software that provides a wide range of tools and services to help businesses manage their customer interactions…

    Automatic Schema Generation, Automation, Benefits, Bulk Data Retrieval, Bulk Operations
    Tim May 26, 2023
    2,294  Views

    Popular Salesforce Videos

    What Is Loyalty Management in Salesforce?

    What Is Loyalty Management in Salesforce?

    Video in Salesforce Training

    Loyalty Management is a strategy employed by companies to focus on acquiring, engaging, and retaining customers. Have a glance at this extract to discover what…

    Salesforce Training, Salesforce Tutorial, Customer Relationship Management, customer service, Salesforce Learning
    Cyntexa Nov 16, 2022
    1,538  Views
    Insert Data in Salesforce Using Standard Controller

    Insert Data in Salesforce Using Standard Controller

    Video in Data

    Standard controllers provides ability to access and interact with structured business data contained in records displays in the proper user interface. Standard controller tasks: controlling…

    Salesforce Apex, Salesforce Objects, Salesforce Controller, Salesforce Standard Controller, Salesforce Components
    Portia Jan 17, 2018
    2,413  Views
    Winter'22 updates for Salesforce Developers

    Winter'22 updates for Salesforce Developers

    Video in Salesforce Training

    Did you know most new features are included with your initial purchase? Explore the latest innovations in the release to maximize your ROI from Salesforce.…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Developers, Salesforce Video
    Rupal Kakkar Oct 18, 2021
    2,072  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.