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 › How to store list of contacts in Salesforce associated to a particular account using Map?

    Tagged: Account, Contact List in Salesforce, Contact Record, Map FinalMap, Map in Salesforce, Salesforce Query, Salesforce sObject

    • Salesforce® Discussions

      How to store list of contacts in Salesforce associated to a particular account using Map?

      Posted by subramanyam subbu on January 10, 2018 at 3:23 AM

      Can you please tell me the query how to store a list of contact associated with an account using Map
      Iam using this below query
      Map FinalMap=new Map[(Select id,(Select lastname from contacts) from account)];

      Throughing errror you cannot store two sobject on a map

      Ajay Prakash replied 8 years, 3 months ago 2 Members · 1 Reply
      • Account
      • Contact List in Salesforce
      • Contact Record
      • Map FinalMap
      • Map in Salesforce
      • Salesforce Query
      • Salesforce sObject
    • 1 Reply
    • Ajay Prakash

      Member
      January 10, 2018 at 4:30 AM

      Hi subramanyam,

      Use below code, it will provide you a map of Account vs list of associated contacts.

      map<Account,list<Contact>> mapOfAccountVsContact = new map<Account,list<Contact>>();
      for(Account accObj : [select id, name, (select id,lastname from contacts) from Account]){
      mapOfAccountVsContact.put(accObj,accObj.Contacts);
      }
      system.debug('mapOfAccountVsContact::'+mapOfAccountVsContact);

    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

    [adinserter block="12"]

    Popular Salesforce Blogs

    One Must Opt For Salesforce Email Automation

    Blog in Salesforce

    There are still various organizations that prefer email marketing campaigns to reach out to their customers in the best way possible. And why not? People…

    Automated Email Campaign, Automated Email-marketing Software, Automated Emails, Automation, Business Strategy
    360 Degree Jun 22, 2021
    2,244  Views
    fast turnover in Salesforce

    Fascinatingly fast turnover in Salesforce

    Blog in Coding and Scripting

    While in the previous article we were talking about a very interesting and fun challenge - however one looks at it, it is a challenge…

    Cloud Computing Salesforce, Salesforce Community, Salesforce Developers, Salesforce Development, Welkin Suite
    The Welkin Suite Aug 18, 2017
    3,833  Views
    customer engagement

    How Salesforce Can Drive Consumer Engagement?

    Blog in Salesforce

    With the rise in popularity of digital ecosystems, communication channels have drastically evolved, and along with it, customer expectations have significantly changed as well. This…

    Businesses, Cloud-managed Services, Communication and Collaboration, Communication Channels, Consumer Engagement
    Apphienz Apr 13, 2021
    2,132  Views

    Popular Salesforce Videos

    Governor Limits in Salesforce | Video Tutorial

    Governor Limits in Salesforce | Video Tutorial

    Video in Salesforce Apex, Salesforce Training

    Watch this amazing video to learn all about Governor Limits in Salesforce and a description of Governor Limits in Salesforce. If you have any doubts…

    Salesforce Training, Salesforce Tutorial, Salesforce Apex, Salesforce Developer, salesforce
    CRS Oct 28, 2021
    3,140  Views
    Salesforce Training Videos For Beginners - 3 | Salesforce Admin  Training

    Salesforce Training Videos For Beginners - 3 | Salesforce Admin Training

    Video in Salesforce Admin

    This Salesforce Training Video will help us in quotation generation and improve customer communication. Generating proposals can be a drag on sales team productivity. Editing…

    Salesforce Service Cloud, Salesforce Online Training, Salesforce Admin Training, Salesforce Administrator Training, Salesforce Admin Beginners Tutorial
    Simplilearn Apr 23, 2019
    2,293  Views
    Why Users Cannot be Deleted from Salesforce | How to Delete User from Salesforce?

    Why Users Cannot be Deleted from Salesforce | How to Delete User from Salesforce?

    Video in Salesforce Stories

    Why users cannot be deleted from Salesforce and how to delete users from Salesforce? Watch this video and learn all about it. Do let us…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Users
    Pooja Jan 28, 2022
    1,686  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.