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
ashok  45ashok 45 

Can we Store Multiple values into Map?

Hi All,


  How can store 6 records in map1?

Can you help me in this, wether i am correct or not. if am wrong please tell me possible way to store 6 records in map?

Here  i want to pass map1 into another method


Map<String,String> map1=Map<String,String>();


list<Custom_Object__c> clist=[select id,name,phone__c,fax__c,country__c from Custom_object__c]; 
System.debug('size is'+clist.size()); // SIZE is 6

for(integer i=0;i<clist.size();i++)
{
 string sname=clist[i].name;
 string sphone=clist[i].phone__c;
 string sfax=clist[i].fax__c;
 string scountry=clist[i].country__c;
 
 map1.put('Name',sname);
 map1.put('Phone',sphone);
 map1.put('Fax',sfax);
 map1.put('Country',scountry);
}

System.debug('size map31 is' +map1.size()); //want to get 6 here, and want map1 can store 6 records


mapvalues(map<string,string> map1);


============

here is the method

public static void mapvalues(map<string,string> map1);
{
 //here i want to insert that 6 records into cust object web_logs__c

//  1. name phone fax country
//  2. name phone fax country
//  3. name phone fax country
//  4. name phone fax country
//  5. name phone fax country
//  6. name phone fax country
}
SRKSRK
Try this SOQL

Map<id,Custom_object__c> map1 = new map<id,Custom_object__c>([select id,name,phone__c,fax__c,country__c from Custom_object__c limit 6]);

system.debug('&!$&@#!@&#&'+ map1.size()); 

and hear the record id will become the key of map


hope it help, this is as per my understding based on what you explaned in above question
JeffreyStevensJeffreyStevens
You could also store a map of maps, or a map of a list.  Like this...

Map<string,list<string>>