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
DeepikareddyDeepikareddy 

Displaying of the value in the salesforce

hi, i have a small query.. if i had  two arrays like :

 map<string, object>  mappingconcept = ' { "data": [ {"country": "usa", "value": "usa-co" },{"country": "Australia", "value": "Aus-Mo" },{"country": "Germany", "value": "Gem-flo" } ] } ';

Onclick of country name, the value should have to apper using the actionsupport, how to proceed with out using selectlist in salesforce thankss
 
Best Answer chosen by Deepikareddy
Prabhat Sharma 6Prabhat Sharma 6
Hi,

Try this.
map<String,Object> objMap= (map<String,Object>)JSON.deserializeUntyped('{"data": [{"country": "usa", "value": "usa-co" },{"country": "Australia", "value": "Aus-Mo" },{"country": "Germany", "value": "Gem-flo"}]}');
List<Object> objList = (List<Object>)objMap.get('data');
map<String,String> countryNameValueMap = new map<String,String>();

for(Object obj : objList){
    map<String,Object> contryMap = (map<String,Object>)obj;
    countryNameValueMap.put((String)contryMap.get('country'),(String)contryMap.get('value'));
}

The countryNameValueMap will give you the below result
 
{Australia=Aus-Mo, Germany=Gem-flo, usa=usa-co}

 

All Answers

Prady01Prady01
Your code statement will give you illegal assignment error.

 Anyhow you can make it like below.

map<string, List<string>> conMap = new manp<string, List<string>>();

 
Prabhat Sharma 6Prabhat Sharma 6
Hi,

Try this.
map<String,Object> objMap= (map<String,Object>)JSON.deserializeUntyped('{"data": [{"country": "usa", "value": "usa-co" },{"country": "Australia", "value": "Aus-Mo" },{"country": "Germany", "value": "Gem-flo"}]}');
List<Object> objList = (List<Object>)objMap.get('data');
map<String,String> countryNameValueMap = new map<String,String>();

for(Object obj : objList){
    map<String,Object> contryMap = (map<String,Object>)obj;
    countryNameValueMap.put((String)contryMap.get('country'),(String)contryMap.get('value'));
}

The countryNameValueMap will give you the below result
 
{Australia=Aus-Mo, Germany=Gem-flo, usa=usa-co}

 
This was selected as the best answer
DeepikareddyDeepikareddy
Hi prabhat sharma,, 

thanks for your reply, its working fine, can u please help me out in creating the Visualforce page.. 
i had used repeat functionality 
<apex:page controller="test1">
  
  <apex:form >
   
   <ul style="list-style-type: none;">
   
    <apex:repeat value="{!countryNameValueMap}" var="a">
    
          <li style="padding:5px;" ><label>{!a}</label></li>
  
<!--how to get the value onclicking --->
  <apex:actionSupport event="Onclick" reRender="fm" action="{!test}" />
  
    </apex:repeat>
    
    <br/>
   
    <apex:outputText id="fm">The selected values are {!selectedvalue}</apex:outputText>
   
   </ul>
  
  </apex:form>
</apex:page>

//can u please he me out to solve the issue thanks!!