0

I have the following code. I would like to create a visualforce page like enter image description here

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?

  • the debug file has the following output: 01:37:57:828 USER_DEBUG [55]|DEBUG|fromJSON:[Data=(cls_Data:[BVDID=NL34179503, CONSOLIDATION_CODE=C2, COUNTRY_ISO_CODE=NL, EMPL=null, NACE2_CORE_CODE=6420, NAME=ROYAL DUTCH SHELL PLC, OPRE=3.568957553100586E11, YEAR_LAST_ACCOUNTS=2007-12-31T00:00:00], cls_Data:[BVDID=GB04366849, CONSOLIDATION_CODE=C1, COUNTRY_ISO_CODE=GB, EMPL=83000.0, NACE2_CORE_CODE=0610, NAME=ROYAL DUTCH SHELL PLC, OPRE=3.45056E11, YEAR_LAST_ACCOUNTS=2019-12-31T00:00:00], – Suel Ahmed Jul 2 at 20:07
  • 1
    welcome to SFSE; please see How to Ask for getting the most from the community. In particular, use edit and show your VF page. YOu are going to need a pageBlockTable or dataTable that iterates over a list – cropredy Jul 2 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.