You need to sign in to do that
Don't have an account?
M Sreekanth
See The Below Class And My requirement is How to get based on place 'SRnagar' i want get city name how to retrive That
Scenario:- Create a Map with cityName as key,and its corresponing
====== places as values
Public class Map_Practice{
public static void mapPrac(){
//*Create a Map with cityName as key,and its corresponing places as values
Map<string,list<string>> myMap = new Map<string,list<string>>();
list<string> Hplaces = new list<string>{'SRnagar','LBnagar','KBHP'};
list<string> Bplaces = new list<string>{'Marthali','Ecity','Whitefield'};
list<string> Cplaces = new list<string>{'Thambaram','ChromePet','TNnagar'};
myMap.put('HYD',Hplaces);
myMap.put('BAN',Bplaces);
myMap.put('CHE',Cplaces);
system.debug('City and Its Places'+myMap);
//Get all the city names
set<string> keys =myMap.keySet();
system.debug('Cityes==>'+keys);
//get all the places
/* *if my map of values is list<string> then we can get all the values list<list<string>>*/
list<list<string>> values = myMap.values();
system.debug('Places==>'+values);
}
}
Please Help Me i am new to salesforce
====== places as values
Public class Map_Practice{
public static void mapPrac(){
//*Create a Map with cityName as key,and its corresponing places as values
Map<string,list<string>> myMap = new Map<string,list<string>>();
list<string> Hplaces = new list<string>{'SRnagar','LBnagar','KBHP'};
list<string> Bplaces = new list<string>{'Marthali','Ecity','Whitefield'};
list<string> Cplaces = new list<string>{'Thambaram','ChromePet','TNnagar'};
myMap.put('HYD',Hplaces);
myMap.put('BAN',Bplaces);
myMap.put('CHE',Cplaces);
system.debug('City and Its Places'+myMap);
//Get all the city names
set<string> keys =myMap.keySet();
system.debug('Cityes==>'+keys);
//get all the places
/* *if my map of values is list<string> then we can get all the values list<list<string>>*/
list<list<string>> values = myMap.values();
system.debug('Places==>'+values);
}
}
Please Help Me i am new to salesforce
All Answers
Please check this code, mark it as best if it resolves your issue. Thanks
public class Student_Exten {
public static void MapPractice2(){
Student s = new student();
s.Name='Sunil';
s.phone='912831281';
s.age=15;
s.rollNo=123;
system.debug('S Data ==> '+s);
Student s1 = new student();
s1.Name='karishma';
s1.phone='9128312341';
s1.age=14;
s1.rollNo=124;
system.debug('S1 Data ==> '+s1);
Student s2 = new student();
s2.Name='Sailu';
s2.phone='9128317371';
s2.age=13;
s2.rollNo=125;
system.debug('S2 Data ==> '+s2);
list<student> sList = new list<student>{s,s1,s2};
system.debug('List Of All Students==> '+sList);
//Create a Map Roll No as Key And Student As Values
Map<integer,student> sMap = new map<integer,student>();
//Add key and values into map through list
for(student stu:sList){
sMap.put(stu.rollNo,stu);
}
system.debug('sMap Key And Values ==> '+sMap);
//Add all The keys into set
set<integer> sKeys=sMap.keySet();
system.debug('Set Of Keys==> '+sKeys);
//Add all The Values into List
list<student> sValues=sMap.values();
system.debug('List Of Values==> '+sValues);
//Get the values based on key
list<student> stuList = new list<student>();
for(integer k:sKeys){
student studValues=sMap.get(k);
if(studValues.rollNo==124){
stuList.add(studValues);
}
}
system.debug('Based on key retrived value is ==> '+stuList);
//get the Key corresponding any values
integer age =13;
integer rNo=Null;
for(integer k:sKeys){
if(sMap.get(k).contains(age)){
rNo=k;
break;
}
}
}
}