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

    JWT Integration

    Integration Through JWT FLOW | Server-to-Server Integration | Salesforce

    Blog in Salesforce integration

    JWT Integration This is used for Server-to-Server Integration Scenarios.  This Flow Uses a certificate to sign the JWT request and doesn’t require explicit user interaction.…

    Certificate and Private Keys, Certificate Signing Request, Client App, data, Debug Log
    Mohit Kumar Dec 12, 2022
    2,664  Views
    3 Salesforce Security Vulnerabilities Companies Should Not Ignore

    3 Salesforce Security Vulnerabilities Companies Should Not Ignore

    Blog in Salesforce

    Gartner estimates that 99% of cloud security failures stem from customer misconfigurations. Recent cybersecurity alerts confirm this trend in enterprise customer relationship management (CRM) environments.…

    Salesforce, Salesforce Consulting
    George Aug 17, 2026
    177  Views
    GDPR

    What Happens When Salesforce Meets GDPR?

    Blog in Salesforce

    Are you using cloud apps like Salesforce, Google G Suite, Microsoft Office 365??? Then under the GDPR impact, you should know a few things in…

    Cloud Apps, Gap Analysis, GDPR, Global Data Protection Regulation, Google G Suite
    Algoworks Jun 29, 2020
    3,175  Views

    Popular Salesforce Videos

    Salesforce Stock Pops on Better-than-expected Earnings and Guidance

    Salesforce Stock Pops on Better-than-expected Earnings and Guidance

    Video in Salesforce Stories

    Salesforce shares rose as much as 3% in extended trading on Wednesday after the enterprise software maker reported fiscal second-quarter earnings and forward guidance that…

    salesforce, Salesforce Video, Tableau, Service Cloud, data analytics
    Nauman Aug 26, 2021
    1,754  Views
    UiPath automation for Salesforce | REST API commands | OAuth2 | Download files | Without activity

    UiPath automation for Salesforce | REST API commands | OAuth2 | Download files | Without activity

    Video in Lightning, Salesforce Automation

    How to send a raw REST API command from UiPath to Salesforce without using custom activities. 0:00 Intro 1:35 OAuth2 4:10 Download files from a case, opportunity, account,…

    Salesforce Training, REST, salesforce, Salesforce Video, Salesforce Learning
    Cristian Dec 14, 2020
    3,187  Views
    Understanding Products & Pricebooks in Salesforce

    Understanding Products & Pricebooks in Salesforce

    Video in Salesforce Training

    In this video, Shrey gave detailed information about products and pricebooks You will also learn: 1. How to add and manage Products in Salesforce? 2.…

    Salesforce Training, Salesforce Tutorial, Salesforce Administrator, salesforce, Salesforce Video
    Jogender Mar 30, 2021
    2,729  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.