function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VKrishVKrish 

Help with Map in custom object

Hi All,

 

I am trying the following:

Map<Id, Account> accMap = new Map<Id, Account>();
Map<Id, Custom__c> cMap = new Map<Id, Custom__c>();
accMap.putAll([select id, Name from Account]);
cMap.putAll([select id, cName__c from Custom__c]);

 It is working perfectly with Account.

But the last line is giving me error saying Map(List<Custom__c>) is not defined.

 

Does putAll method works only with standard objects?

What am I missing?

Best Answer chosen by Admin (Salesforce Developers) 
seattle_devseattle_dev

Try this:

 

Map<Id, Custom_Object__c> myMap = new Map<Id, Custom_Object__c>([Select Custom_Field__c From Custom_Object__c]);

All Answers

seattle_devseattle_dev

Try this:

 

Map<Id, Custom_Object__c> myMap = new Map<Id, Custom_Object__c>([Select Custom_Field__c From Custom_Object__c]);

This was selected as the best answer
VKrishVKrish

It works. Thanks!

Anyway I couldnt understand why putAll method doesnt work with custom objects