I have made an external API call (JSON type). And I have stored the fields and values in a Map<String, List> object.
Now I have to created a visual force page that displays the Map in columnwise format.
Please refer to the below code:
public with sharing class testClass{
// Initialization
public string companyName{get; set;}
public void showRecord(){
Map<String, List<Object>> pageToWordMap = new Map<String, List<Object>>();
// Input from the user
String str = companyName; // input from Visual force page
String query = '';
//create a rest endpoint
string requestEndPoint = '***** end point *******' ;
// requests
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(requestEndPoint);
request.setMethod('GET');
request.setHeader('ApiToken', '*********************');
request.setHeader('Accept', 'application/json');
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200 && response.getBody() != null){
Map<String, Object> results = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
List <Object> data = (List<Object>)results.get('Data');
// for loop
for(Object dta : data){
// getting the attributes of data
Map<String, Object> attributes = (Map<String, Object>) dta;
// now loop through the data
for(String lst : attributes.keyset()){
// handle response
String indexKey = lst;
if(!pageToWordMap.containsKey(indexKey)){
// add the key and new list
pageToWordMap.put(indexKey, new List<Object>());
}
// get the key and add the value
pageToWordMap.get(indexKey).add(attributes.get(indexKey));
}
// for debug purpose
/*
for(String curPage: pageToWordMap.keySet())
{
String key = curPage;
String val = (String)pageToWordMap.get(curPage);
System.debug(key+'-----'+val);
} */
}
}
}
}
The Visualforce code, that I am trying is:
<apex:page controller="testClass" showHeader="false" sidebar="false">
>
> <apex:form>
> <apex:pageBlock title="Company Search">
> <apex:pageBlocksection >
> Please enter the company name <apex:inputText value = "{! companyName}"/>
> <apex:commandButton action="{! showRecord}" value="submit"/>
> </apex:pageBlocksection>
> </apex:pageBlock>
> <apex:pageBlock title="The Data">
> <apex:pageBlockTable value = "{! pageToWordMap}" var = "json">
> <apex:column headerValue="Name" value="{! json.NAME}"/>
> </apex:pageBlockTable>
> </apex:pageBlock>
> </apex:form> </apex:page>
I am new to APEX programming, and now I am not able to figure out how to create the record columns.
The error is ***
Unknown property 'testClass.pageToWordMap'
The column header names are:
- NAME
- BVDID
- COUNTRY_ISO_CODE
please help?????