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

    application solution

    Popular Salesforce Blogs

    Top Salesforce Consulting Companies for CRM Excellence

    Blog in Salesforce Consultant

    Salesforce not only stands tall in the CRM world but is also the go-to for innovation and efficiency. It's not just a platform; it's a…

    Salesforce, Salesforce Companies, Salesforce Consultants, Salesforce Consulting Companies, Salesforce Consulting Services
    Samuel Feb 23, 2024
    1,663  Views
    salesforce duplicate management

    Salesforce Duplicate Management: Dirty Data Handled Well!

    Blog in Others

    If you have dirty data, your Salesforce Cadillac has the potential to bring your entire organization to a screeching halt. Fabricating business decisions based on…

    AppExchange, Business, Contact, DATA.com, Dirty Data
    Algoworks Aug 2, 2019
    1,462  Views

    NetSuite implementation | SixLakes Consulting

    Blog in Salesforce Consultant

    Introduction A successful NetSuite implementation is the foundation for building an efficient, data-driven, and scalable business environment. It involves a strategic process of planning, configuration, customization, data…

    SixLakes Consulting Jan 20, 2026
    36  Views

    Popular Salesforce Videos

    Top 3 Reasons to Use Salesforce Checkout

    Top 3 Reasons to Use Salesforce Checkout

    Video in Salesforce Products

    Watch this video to understand your Salesforce contract information, make payments, and add additional licenses with Salesforce Checkout. This video discusses about the top 3…

    Salesforce Training, salesforce, Salesforce Video, salesforce product, Salesforce Checkout
    Rupal Kakkar May 6, 2020
    1,441  Views
    Wow Your Customers with Salesforce Customer 360

    Wow Your Customers with Salesforce Customer 360

    Video in Salesforce Stories

    Salesforce Customer 360 helps companies unite their teams to deliver amazing wow-worthy experiences beyond customer expectations.

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Customer 360
    Nauman Mar 10, 2022
    506  Views
    3 Easy to Use Salesforce Field Service Dashboards | AblyPro- Live Webinar

    3 Easy to Use Salesforce Field Service Dashboards | AblyPro- Live Webinar

    Video in Salesforce Field Service Platform

    Watch AblyPro's exciting webinar video on Salesforce Field Service Reports & Dashboards. Discover how these powerful tools can drive efficiency and cut support costs for…

    Salesforce Field Service Platform, Salesforce Field Service, Service Cloud Specialist, Reports and Dashboards, Field Service Management
    AblyPro Jul 3, 2024
    626  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.