You need to sign in to do that
Don't have an account?

how to write map and list with country and languages
Hi everyone,
Can anyone please guide my how to write a map<string> and list<string> together.please find below code and help me on this issue.
Map<String, Map<String, List<String>>> countryMap = new Map<String, Map<String, List<String>>> {'Germany' => 'German', 'Spain' => 'Spanish' , 'France' => 'French' , 'UnitedStates' => 'English' , 'UnitedStates' => 'Spanish' , 'Canada' => 'English' , 'Canada' => 'French'};
for(String c : newCountries){
for(String l : newLanguages){
if(countrymap.containskey(c) && !Countrymap.get(c).contains(l)){
error = true;
account.adderror( 'country ' + c + ' does not support language ' + l);
return;
}
}
}
Thanks inadvance,
P.Balu
Can anyone please guide my how to write a map<string> and list<string> together.please find below code and help me on this issue.
Map<String, Map<String, List<String>>> countryMap = new Map<String, Map<String, List<String>>> {'Germany' => 'German', 'Spain' => 'Spanish' , 'France' => 'French' , 'UnitedStates' => 'English' , 'UnitedStates' => 'Spanish' , 'Canada' => 'English' , 'Canada' => 'French'};
for(String c : newCountries){
for(String l : newLanguages){
if(countrymap.containskey(c) && !Countrymap.get(c).contains(l)){
error = true;
account.adderror( 'country ' + c + ' does not support language ' + l);
return;
}
}
}
Thanks inadvance,
P.Balu
For Slecting single language for single country it was working fine.
public class testCode {
public static void validateCode(){
List<String> Countries = new List<String>();
List<String> Languages = new List<String>();
Countries.add('UnitedStates');
Languages.add('Telugu');
Map<String, List<String>> countryMap = new Map<String, List<String>>{
'Germany' => new List<String>{'German'},
'Spain' => new List<String>{'Spanish'},
'France' => new List<String>{'French'},
'UnitedStates' => new List<String>{'English', 'Spanish'},
'Canada' => new List<String>{'English', 'French'}};
for(String c : Countries){
for(String l : Languages){
if(countryMap.containskey(c) && !countryMap.get(c).contains(l)){
system.debug( 'Country ' + c + ' does not support language ' + l);
}
}
}
}
}
Thanks For everyone for helping foe this.
All Answers
I have gone through your problem please refer below process:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Thanks You so much for reply.For cites and statesit will be fine but writing for countires and language it was very diffcult to comparing.
public class testCode {
public static void validateCode(){
List<String> Countries = new List<String>();
List<String> Languages = new List<String>();
Map<String, List<String>> countryMap = new Map<String, List<String>>{
'Germany' => new List<String>{'German'},
'Spain' => new List<String>{'Spanish'},
'France' => new List<String>{'French'},
'UnitedStates' => new List<String>{'English', 'Spanish'},
'Canada' => new List<String>{'English', 'French'}};
Countries.add('Germany');
Languages.add('German');
for(String c : Countries){
for(String l : Languages){
if(countrymap.containskey(c) && !c.equals(l)){
system.debug( 'country ' + c + ' does not support language ' + l);
return;
}
}
}
}
}
but here when i am using debug it was showing germany does not support language german ike that.so please check and update on this.
Thanks in advance,
p.Balaji
For Slecting single language for single country it was working fine.
public class testCode {
public static void validateCode(){
List<String> Countries = new List<String>();
List<String> Languages = new List<String>();
Countries.add('UnitedStates');
Languages.add('Telugu');
Map<String, List<String>> countryMap = new Map<String, List<String>>{
'Germany' => new List<String>{'German'},
'Spain' => new List<String>{'Spanish'},
'France' => new List<String>{'French'},
'UnitedStates' => new List<String>{'English', 'Spanish'},
'Canada' => new List<String>{'English', 'French'}};
for(String c : Countries){
for(String l : Languages){
if(countryMap.containskey(c) && !countryMap.get(c).contains(l)){
system.debug( 'Country ' + c + ' does not support language ' + l);
}
}
}
}
}
Thanks For everyone for helping foe this.