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
Chitral ChaddaChitral Chadda 

Help about maps

for (FeedItem objFeedItem: trigger.new)
 {
    
    //Check it is user
    if(objFeedItem.ParentId!=null && String.valueOf(objFeedItem.ParentId).startsWith('005'))
    {
        accIdSet.add(objFeedItem.ParentId);       
    }
 }
 
 Map<Id,User> userMap=null;
 if(accIdSet.size()>0)
 {
   userMap = new Map<Id,User>([select Id,AccountId__c from User where Id in :accIdSet]);
  

IN this we did not put anoything in msp using map.put( someting,something);
we use query:  userMap = new Map<Id,User>([select Id,AccountId__c from User where Id in :accIdSet]);

map<id,user> ====> serach value is id and what it wud return is user .
so i am not able to understand  this statement 
userMap = new Map<Id,User>([select Id,AccountId__c from User where Id in :accIdSet]);
are we putting anything inside the map   and whats the use of writing query here?/



also,
if(objFeedItem.type=='QuestionPost')
     {
         objCase = new Case();
         objCase.Subject=objFeedItem.Title;
         objCase.Description=objFeedItem.Body;
         objCase.Origin = 'Portal';
         objCase.Type = 'Portal Enquiry';
         
         Id accId = userMap.get(objFeedItem.ParentId).AccountId__c;
         if(accId!=null)
         {
             objCase.AccountId = accId;
             lstCase.add(objCase);

in this line
 Id accId = userMap.get(objFeedItem.ParentId).AccountId__c;
it wud return the id of user? cz this is what we used in map<id,user>

 
Best Answer chosen by Chitral Chadda
Deepak Kumar ShyoranDeepak Kumar Shyoran
First line which you have mentioned is 
userMap = new Map<Id,User>([select Id,AccountId__c from User where Id in :accIdSet]);
is used to create a Map from a SOQl and this will always return the Map of records from object on which you're firing SOQL with Id as a key and records with selected field as a value.

Second yes Id accId = userMap.get(objFeedItem.ParentId).AccountId__c; will return Account Id from User by fetching it from above userMap which you have created.