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, 8 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 Nonprofit Cloud vs. NPSP: Which One to Choose?

    Salesforce Nonprofit Cloud vs. NPSP: Which One to Choose?

    Blog in Salesforce Products

    Table of Contents Introduction Nonprofit Success Pack (NPSP) Salesforce Nonprofit Cloud Key Differences between Salesforce Nonprofit Cloud vs. NPSP Conclusion (Salesforce Nonprofit Cloud vs. NPSP)…

    Community Support, Complexity Features, Comprehensive Suite, Constituent Management, Customizable CRM
    Kizzy Consulting May 23, 2024
    887  Views
    Salesforce Experts for CRM Optimization | 7 Warning Signs.

    7 Signs Your Business Needs Salesforce Experts for CRM Optimization and Growth

    Blog in Salesforce

    If your team is fighting the system instead of working through it, you likely need Salesforce experts for CRM optimization before the gap gets any…

    CRM Optimization, CRM ROI, Salesforce Automation, Salesforce Consulting Services, Salesforce CRM Optimization
    Shivam Sep 4, 2026
    93  Views
    Salesforce Pardot

    Getting Started With Salesforce Pardot | The Basics

    Blog in Others, Salesforce Products

    Pardot Pardot is Salesforce's B2B selling automation robotization arrangement. In case you're a business that offers to various organizations (or B2B), Pardot can computerize your…

    Associations, Automation Robotization, B2B Selling, Best Possibilities, Business
    Ratnesh Apr 9, 2021
    3,914  Views

    Popular Salesforce Videos

    Code Review in Salesforce

    Code Review in Salesforce

    Video in Salesforce Training

    Code Review and Code Quality in Salesforce 0:00 Introduction 0:44 What is code review? 1:22 Why we need code review 3:33 Basic code review 4:12…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Prafull Jan 3, 2022
    2,146  Views

    Salesforce Video Wall

    Video in Others

    Salesforce approached Obscura with the opportunity to create imaginative media for the 107’ long LED video wall in the lobby of their flagship San Francisco…

    Salesforce Video Wall, Salesforce Stories, Life at Salesforce, Salesforce Tower, Salesforce Office
    Abhay Mar 22, 2018
    2,294  Views
    Salesforce CPQ Product Bundles

    Salesforce CPQ Product Bundles

    Video in Others, Salesforce Training

    Salesforce CPQ product bundles. See how product bundles work with features and options. Also including an option constraint to prevent incorrect configuration. Watch this video…

    Salesforce Training, salesforce, Salesforce CPQ, CPQ, Salesforce Video
    Engage Systems Sep 29, 2020
    4,430  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.