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

    Apex Triggers in Salesforce Here’s What you Need to Know

    Apex Triggers in Salesforce | Here’s What you Need to Know

    Blog in Salesforce

    What are Apex triggers? Apex triggers permit custom moves to be done before or after data manipulation language (DML) activities arise in Salesforce, such as…

    Apex Triggers, API, Before Insert, Before Trigger, Bulkified Trigger
    Nikhil Kumar Feb 8, 2023
    1,895  Views

    Salesforce User Stories: Salesforce Adoption Experience of FinTech Leaders Globally

    Blog in Salesforce Stories

    The fintech market is substantially evolving and has an expected value of $698.48 billion by 2030, a considerable contrast to its $110.57 billion valuation in…

    Application Submissions, Automated Client Account Openings, Automated Workflows, Automation, Banking
    Sparkybit Dec 11, 2023
    1,150  Views

    The Future is Prompt: Salesforce Prompt Builder in 2025 and Beyond

    Blog in Others

    The buzz around generative AI isn't fading; it's evolving, integrating deeper into our daily workflows. For Salesforce users, this evolution is epitomized by Prompt Builder,…

    Cloudy Aug 1, 2025
    359  Views

    Popular Salesforce Videos

    Getting Business Insights From Telephony Data in Salesforce

    Getting Business Insights From Telephony Data in Salesforce

    Video in Sales

    Big Data, Data Analytics and Data mining are big terms that often sound like they are only for the ‘giant corporation‘ and put people off…

    salesforce, Data Integration, Saleforce Big Data, CTI, phone
    Ian Mar 19, 2020
    1,520  Views
    How to Set Up Salesforce Knowledge in Service Cloud

    How to Set Up Salesforce Knowledge in Service Cloud

    Video in Salesforce Cloud Platform

    Help your customers and agents find answers they are searching for faster with Salesforce Lightning Knowledge. In this video, we will review: - All components…

    Salesforce Training, Salesforce Tutorial, Salesforce Lightning, salesforce, salesforce knowledge
    Prafull Apr 19, 2021
    2,924  Views
    What is Campaign Member in Salesforce? | How to add Leads and Contacts in Campaign object's record?

    What is Campaign Member in Salesforce? | How to add Leads and Contacts in Campaign object's record?

    Video in Salesforce Training

    This video explains Campaign Members in-depth. Let's discuss the following things in this video: 1. What is the significance of Campaign members in Salesforce? 2.…

    Salesforce Training, Salesforce Records, salesforce, Salesforce Objects, Salesforce Leads
    deepti jain Nov 20, 2018
    2,134  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.