I have the following code. I would like to create a visualforce page like
Please refer to the apex class code below:
public with sharing class fromJSON{
public string companyName{get; set;}
public cls_SearchSummary SearchSummary;
public cls_Data[] Data;
class cls_SearchSummary {
public Integer TotalRecordsFound; //47796
public Integer Offset; //0
public Integer RecordsReturned; //100
public cls_DatabaseInfo DatabaseInfo;
//public cls_Sort Sort;
}
class cls_DatabaseInfo {
public String ReleaseNumber; //198
public String UpdateNumber; //198001
public String UpdateDate; //2020-06-26T00:00:00
public String VersionNumber; //129.00
}
class cls_Sort {
//public String DESC; //OPRE
}
class cls_Data {
public String NAME; //ROYAL DUTCH SHELL PLC
public String BVDID; //NL34179503
public String COUNTRY_ISO_CODE; //NL
public String NACE2_CORE_CODE; //6420
public String CONSOLIDATION_CODE; //C2
public String YEAR_LAST_ACCOUNTS; //2007-12-31T00:00:00
public Double OPRE; //356895755310.0586
public Double EMPL;
}
public void showRecord(){
fromJSON lst = new fromJSON();
String str = companyName;
//create a rest endpoint
string requestEndPoint = '************************************' ;
// 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){
lst = fromJSON.parse(response.getBody());
}
System.debug(lst);
}
public static fromJSON parse(String json){
return (fromJSON) System.JSON.deserialize(json , fromJSON.class);
}
}
The VF page code is below:
<apex:page controller="fromJSON" 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 = "{! lst}" var = "json">
<apex:column headerValue="Name" value="{! json[NAME]}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
& the debug file output is:
The column header names that needs to be on the table:
- NAME,BVDID, COUNTRY_ISO_CODE, NACE2_CORE_CODE, CONSOLIDATION_CODE, YEAR_LAST_ACCOUNTS, OPRE, EMPL
I have 3 days of experience in APEX and VF Coding. So any mistakes, please point it out and please help me. I am not able to figure out how to make the page?