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

    Where to Learn Salesforce Admin Training Online?

    Blog in Salesforce

    To start anything, maybe from scratch or to attain an advanced level of knowledge, it is important to know various resources that can help you…

    Salesforce, salesforcedeveloper
    Ray brad Aug 1, 2025
    401  Views
    Salesforce For Business

    Top 7 Reasons To Choose Salesforce For Your Business

    Blog in Salesforce

    Description: Salesforce is one of the world leaders in the development of cloud-based CRM solutions. We'll talk about why it is important for your business.…

    Applications, Automated Scripts, Best Solutions, Business, Business Requirements
    Theresa Cofield Mar 23, 2021
    4,407  Views

    Top Features and Updates from Salesforce Winter’25 Release

    Blog in Salesforce Releases

    Get ready to embrace the excitement of the Salesforce Winter '25 Release! This season's update is like the first snowfall, bringing a flurry of innovative…

    Salesforce Winter Release
    Grazitti Aug 1, 2025
    482  Views

    Popular Salesforce Videos

    How To Use Salesforce Campaigns in Pardot

    How To Use Salesforce Campaigns in Pardot

    Video in Salesforce Stories

    Learn campaign basics to help you plan your marketing strategy. In this video, Pardot experts guide you in: - Defining campaigns in Pardot and Salesforce…

    Salesforce Training, salesforce, Salesforce Video, Campaign Members, Salesforce Learning
    Pooja May 19, 2021
    3,289  Views
    What benefits Salesforce Email integration provides for my business?

    What benefits Salesforce Email integration provides for my business?

    Video in Salesforce Integration

    This video puts light on the benefits of Salesforce Email Integration for Business. Every aspect of Email Integration is provided and discussed in detail along…

    Salesforce Reports, Salesforce Integration, Salesforce Records, Salesforce CRM, Salesforce Integration Cloud
    Nauman Nov 22, 2018
    2,552  Views
    Before Delete Trigger in Salesforce Flows - Winter '21 update

    Before Delete Trigger in Salesforce Flows - Winter '21 update

    Video in Salesforce Training

    In this video, I'm talking about one of the new features of the Salesforce Winter '21 flow builder i.e is before delete trigger. Watch and…

    Salesforce Training, Salesforce Tutorial, Salesforce Video, Salesforce Learning, Flow Builder
    Shubham Jan 22, 2021
    3,667  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.