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

    Salesforce Ohana

    Salesforce Ohana - Community and Culture

    Blog in Salesforce Releases

    Salesforce builds a culture within its organization and also with its customers, partners, and employees that it calls Ohana. Salesforce builds its culture through the…

    Salesforce, Salesforce Community, Salesforce culture, Salesforce Ohana, Salesforce Trust
    JanBask Jul 20, 2018
    5,886  Views

    Salesforce Quotes Best Practices for Quotation Templates

    Blog in Salesforce Tools

    A quotation template is a professional document outlining your products or services, pricing, and terms. It’s more than just a price list; it’s a strategic…

    Configure Price Quote, CPQ, cpq-objects, cpq-solution, Document Template
    Sculptor CPQ Sep 3, 2024
    381  Views
    Customer Communication Tools

    6 Perfect Customer Communication Tools for Maintaining Relationships | Salesforce

    Blog in Salesforce Tools

    According to a Hubspot survey, 68% of customers don’t mind paying more than the market average for the products or services of a company providing…

    Attention-demanding Tasks, Best Messengers for Customer Service, Better Retention, Business, Business Needs
    Evelina Brown Sep 23, 2021
    3,199  Views

    Popular Salesforce Videos

    Introduction to Lightning Web Components: A Practical Example

    Introduction to Lightning Web Components: A Practical Example

    Video in Lightning, Salesforce Training

    In this session, Alba Rivas will show how to build a page step-by-step in Lightning Web Components. You will learn some of the basics of…

    Salesforce Training, Salesforce Tutorial, Salesforce Developers, Lightning Web Components, Framework
    Jogender Nov 30, 2020
    1,796  Views
    APIs and Integration for the Salesforce Platform

    APIs and Integration for the Salesforce Platform

    Video in Salesforce Integration

    Watch this session to learn how you can integrate with the Salesforce Platform. We'll demonstrate features, APIs, and techniques for integrating with Salesforce Core, Heroku,…

    Salesforce Training, Salesforce Tutorial, Salesforce Integration, salesforce platform, Salesforce Video
    Abhishek Apr 28, 2021
    2,410  Views
    How Will Salesforce Career Look Like 3 Years From Now?

    How Will Salesforce Career Look Like 3 Years From Now?

    Video in Salesforce Stories

    In this video, Shrey shares his opinions about How will Salesforce career look like 3 years from now. Watch and learn. If you have any…

    Salesforce Training, Salesforce Tutorial, Salesforce Certification, Salesforce Developer, salesforce
    Jogender Feb 25, 2021
    1,268  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.