Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class calloutViewer_Controller {
- public String requestEndpoint {get;set;}
- public String accountodel {get;set;}
- public String createnewtask {get;set;}
- public String requestMethod {get;set;}
- public String requestBody {get;set;}
- public String responseStatus {get;set;}
- public Integer responseStatusCode {get;set;}
- public String responseBody {get;set;}
- public RFAPI.responseResource2 response2 {get;set;}
- deserializedQuestions {get;set;}
- public List<RFAPI.questionResource2> deserializedQuestions2 {get;set;}
- public void callout2(){
- httpResponse res2 = RFAPI.callout2(requestMethod, requestEndpoint, requestBody);
- responseStatus = res2.getStatus();
- responseStatusCode = res2.getStatusCode();
- responseBody = res2.getBody();
- public void deserializeQuestions2(){
- if ( string.isNotBlank(responseBody) ){
- response2 = (RFAPI.responseResource2)JSON.deserialize(responseBody,RFAPI.responseResource2.class);
- deserializedQuestions2 = response2.items2;
- }
- }
- public with sharing class RFAPI {
- public static String BASE_URL = 'My api url';
- public static httpResponse callout2(String httpMethod, String endpoint, String body){
- String token = 'My API token';
- httpRequest req = new httpRequest();
- req.setHeader('X-RFToken', token);
- req.setMethod(httpMethod);
- req.setEndpoint(endpoint);
- system.debug(res2.toString());
- system.debug(res2.getBody());
- return res2;
- }
- public static responseResource2 deserialize(httpResponse res2){
- return (responseResource2)JSON.deserialize(res2.getBody(),responseResource2.class);
- }
- public class responseResource2 {
- public List<questionResource2> items2{get;set;}
- }
- public class questionResource2 {
- public Timestamps timestamps {get;set;}
- public Counts counts {get;set;}
- public Entity entity {get;set;}
- }
- public class Timestamps {
- public String firstSeen {get;set;}
- public String lastSeen {get;set;}
- }
- public class Entity {
- public String id {get;set;}
- public String name {get;set;}
- public String type_Z {get;set;}
- }
- public class Counts {
- public Integer returned {get;set;}
- public Integer total {get;set;}
- }
- <apex:pageBlockSection columns="1" title="JSON Deserializer" rendered="{!deserializedQuestions2 != null}" collapsible="false" >
- <apex:pageBlockTable value="{!deserializedQuestions2}" var="i" >
- <apex:column headerValue="Owner" style="width:100px;" >
- </apex:column>
- <apex:column headerValue="Question Id" style="width:75px;" >
- <apex:outputText value="{!i.timestamps.firstseen}" />
- </apex:column>
- <apex:column headerValue="Creation Date" style="width:75px;" >
- <apex:outputText value="{!i.timestamps.lastseen}" />
- </apex:column>
- <apex:column headerValue="View Count" style="width:75px;" >
- <apex:outputText value="{!i.entity.id}" />
- </apex:column>
- <apex:column headerValue="Answer Count" style="width:75px;" >
- <apex:outputText value="{!i.entity.name}" />
- </apex:column>
- <apex:column headerValue="Score" style="width:50px;" >
- <apex:outputText value="{!i.entity.type_Z}" />
- </apex:column>
- <apex:column headerValue="Score" style="width:50px;" >
- <apex:outputText value="{!i.counts.returned}" />
- </apex:column>
- <apex:column headerValue="Score" style="width:50px;" >
- </apex:column>
- </apex:pageBlockTable>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement