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

    application solution

    Popular Salesforce Blogs

    Can Salesforce Implementation Partner Be the Missing Piece of the Puzzle?

    Blog in Salesforce Implementation

    With innovation in technology, enterprises are leveraging a go-digital first approach with the best-in-class and out-of-the-box software. And, Salesforce CRM happens to be one of…

    Community Cloud, CRM, Customer Data, Customization, Sales Cloud Implementations
    Carol Feb 13, 2023
    1,423  Views

    Salesforce Marketing Cloud Personalization Overview

    Blog in Salesforce Cloud Platform

    Suppose you've attracted leads to your website or app. Some of them converted into prospects. You carry on gathering data, but they keep unsubscribing or…

    Audience Segments, Behavioral Data, Cloud Personalization, Cross-Selling Tools, Customer Data Platform
    Twistellar Jun 17, 2024
    546  Views

    Salesforce Lightning Web Components Developer Guide Chapter 2: Markup Basics

    Blog in Lightning

    Here is the second article in our series, where we delve into the LWC basics. In the previous article, we discussed the basic principles and…

    Communication, Communication Between LWC Components, Conditional Elements Rendering, Conditional Rendering, Consistent Appearance
    Sparkybit Dec 11, 2023
    1,062  Views

    Popular Salesforce Videos

    Experience the Most Flexible, Easiest, and Securest Way to Integrate Salesforce and Jira

    Experience the Most Flexible, Easiest, and Securest Way to Integrate Salesforce and Jira

    Video in Salesforce Integration

    Integrate standard and custom Salesforce objects with Jira to strengthen cross-functional collaboration and deliver a top-notch customer experience. Fast-Track Your Journey to Attaining Customer Centricity…

    salesforce, Salesforce Video, Salesforce Learning, Customer Experience, jira
    Shubham Oct 14, 2020
    2,004  Views
    How Salesforce AppExchange Can Boost Your Application's Marketing ?

    How Salesforce AppExchange Can Boost Your Application's Marketing ?

    Video in Others

    Explore the key benefits of AppExchange, the largest business app marketplace, and discover how you can tap into its vast ecosystem of potential customers. In…

    Salesforce Developer, salesforce, Salesforce Hulk, Salesforce Webinar, Salesforce Video
    Cyntexa Sep 12, 2023
    846  Views
    Salesforce Spring ‘21 Release Notes Highlights & Summer ‘21 Preparation

    Salesforce Spring ‘21 Release Notes Highlights & Summer ‘21 Preparation

    Video in Salesforce Stories

    Spring ‘21 Release Notes Highlights & Summer ‘21 Preparation In this session we discussed 00:00​ Bella Vista, Western Sydney Developer Group Overview 03:30​ Andrew Whitten…

    Salesforce Training, Salesforce Video, Salesforce Learning, Release Notes, Salesforce Release
    Rupal Kakkar May 7, 2021
    2,072  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.