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

    Breaking Down the Basics of Salesforce MuleSoft

    Blog in Salesforce, Salesforce Products

    We all know the feeling. You've got a to-do list, but somehow it never seems to get any shorter. Your IT team is no different.…

    Application Integration, Application Network, Applications, Automate Sales, Benefits of MuleSoft
    Apphienz Nov 22, 2022
    2,135  Views

    11 Top Training Resources To Master Salesforce

    Blog in Salesforce Tutorial

    As the most powerful customer relationship management (CRM) resource in sales and marketing, Salesforce is in demand helping subscribers increase contacts and sales revenue every…

    learn salesforce, Salesforce Certification, salesforce for beginners, Salesforce Guide, Salesforce Training
    Nirmal May 15, 2018
    10,105  Views

    4 Ways Salesforce Can Help Enhance Your Field Work

    Blog in Salesforce

    Are you a company that provides field service? If so, you understand how important it is to offer the best quality in your work. After…

    Audience, Business Objectives, Cloud-based, Cloud-Based Customer Service, Cloud-based ecosystem
    Apphienz Apr 1, 2022
    1,896  Views

    Popular Salesforce Videos

    Which Salesforce Certifications are Really Important?

    Which Salesforce Certifications are Really Important?

    Video in Salesforce Certifications

    If you really want to know which Salesforce certifications are really important then this video is for you. If you have any doubts or concerns,…

    Salesforce Training, Salesforce Tutorial, Salesforce Certifications, Salesforce Jobs, salesforce
    Jogender Mar 3, 2022
    3,090  Views
    How To Create Workflow Rules In Salesforce | Salesforce Workflow Rules

    How To Create Workflow Rules In Salesforce | Salesforce Workflow Rules

    Video in Salesforce Training

    This video walks through the steps to create a Workflow Rule within the Process Automation section of Lightning Settings in Salesforce. Get answers to the…

    Salesforce Training, Salesforce Tutorial, Salesforce Lightning, Process Automation, salesforce
    Algoworks Sep 16, 2021
    1,487  Views
    How to Add Custom Fields on Custom Object in Salesforce?

    How to Add Custom Fields on Custom Object in Salesforce?

    Video in Salesforce Admin

    Watch this video to learn all about how to add custom fields on custom objects in Salesforce. If you have any doubts do let us…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Prafull Feb 2, 2022
    2,297  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®.

    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.