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

    Popular Salesforce Blogs

    salesforce customization

    How Salesforce Customization Services Can Help Your Business

    Blog in Salesforce

    Salesforce is known to have thousands of features used by businesses, along with customization options. Off-the-shelf Salesforce solutions might initially help a business but, moving…

    API, Automation Ttools, Bulk Data, Bulk Data Processing, Business
    360 Degree Aug 3, 2021
    1,907  Views
    salesforce reporting

    Top New Features in Salesforce Reporting

    Blog in Analytics

    In this blog, we are going to focus on a couple of the newer features in Salesforce Analytics that have been released over the past…

    Dashboard Components, Grand Totals, Lightning Table, Opportunity Report, Permission Set
    Stimulus Consulting Jul 6, 2020
    5,981  Views

    Why Growing Businesses Need CRM That Adapts to Their Processes

    Blog in Salesforce customization

    Most growing businesses reach a point where their CRM system becomes an obstacle rather than an asset. The platform they selected during early growth—often chosen…

    Shivam Jul 7, 2026
    624  Views

    Popular Salesforce Videos

    Get Started with Process Builder

    Get Started with Process Builder

    Video in Salesforce Development

    Get started with process builder -- and replace that ridiculously and ever-growing list of workflow rules with easier to understand, more extensible processes. This video…

    Salesforce Development, Salesforce Process Builder, Process Automation, Salesforce Lightning Process Builder, Process Builder
    Deepti May 17, 2018
    1,996  Views
    Financial Services Cloud – Release Readiness LIVE, Summer '19

    Financial Services Cloud – Release Readiness LIVE, Summer '19

    Video in Salesforce Cloud Platform

    Hear about some of the new and exciting features that you can expect from Financial Services Cloud in the Summer '19 Release. Highlights include: -…

    Salesforce Records, Cloud Computing, Salesforce Cloud, Salesforce CRM, Financial Services Cloud
    Abhay Jul 12, 2019
    2,206  Views
    What is Salesforce? | Why is it So Good ? | High Demand Skills

    What is Salesforce? | Why is it So Good ? | High Demand Skills

    Video in Salesforce Stories

    In this video, Technical Suneja explains what Salesforce is and why it is such a valuable skill set to have. He goes into detail about…

    Salesforce Training, Salesforce Tutorial, Salesforce Functions, Salesforce Learning, Accounts in Salesforce
    Rahul kapoor Sep 15, 2022
    2,347  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.