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
sf_evolutionsf_evolution 

Rerender from HTTP Callout data

Hi all,

I am updating a datatable from data that I receive from an external HTTP Callout API.

The only way I sem to be able to get the data to display on my VF page is if
I query for the external ID from a commandbutton on the page, and have the button
rerender the datatable.

What I would like is for the previous page to just call the desired page with the
customerID and have it render the datatable with the customer ID and be done with it.

Specifically, this works:

 

Controller-relevant code:

public class ListingIdFindController {

    public String strResponse { get; set; }
         String[] listListings = new List<String>();
         
         public class Listings {
             public String ListingID{get;set;}
             public String StreetID{get;set;}
             public String theURL{get;set;}
             public String PrimaryCategoryId{get;set;}
             public String PrimaryCategoryValue{get;set;}
             public String MOP{get;set;}
             public String MOPID{get;set;}
             }      
   [---]   
   
   public void getParameters() {
   
    public class ListingId {
         public String status;
         List<jsonCategories> existingBusinesses;
         List<jsonAccounts > activeBillingAccounts;
         List<jsonPrimaryCategories > primaryTags;
         }

   [---]
         String strTargetListing = ApexPages.currentPage().getParameters().get('CustId');
	 String endpoint = 'https://api-endpoint.com/salesforce/automation/api/lookups?';
	 endpoint += 'customerId=' + EncodingUtil.urlEncode(strTargetListing, 'UTF-8');                
	 request.setMethod('GET');
	 request.setEndPoint(endpoint);
	 System.debug('endpoint: ' + endpoint);

	 HttpResponse response = httpProtocol.send(request);
 	 String strResponse = response.getBody();
	
	 System.debug('strResponse : ' + strResponse );                
	 theListing = (ListingId ) JSON.deserialize(strResponse , ListingId.class);   

	//  -- [Fill-in class Listings with JSON-deserialized data]
	ListingValues = theListing;
	}	
}

 ... And my VF page just reads the public object

 

<apex:page controller="ListingIdFindController" id="ListingIdFindPage">
<apex:form id="ListingIdFindForm">
<apex:pageBlock Title="Search Listing By CID">
    <apex:inputText label="CID: "   value="{!strTargetListing}" />
    <apex:commandButton action="{!getParameters}" value="Go" id="FindListingsButton" rerender="detail_s,detail_p" />
</apex:pageBlock>

<apex:pageBlock Title="Listings Results-Please select a listing">
   <apex:pageBlockSection title="Listings" columns="3" >
      <apex:dataTable value="{!ListingValues}" var="list" id="detail_s" width="800px">
         <apex:column width="25%">
            <apex:facet name="header">Listing ID</apex:facet>
            <apex:outputText value="{!list.ListingID}"/>
         </apex:column>

         <apex:column width="40%">
            <apex:facet name="header">Address</apex:facet>
            <apex:outputText value="{!list.StreetId}"/>
         </apex:column>

         <apex:column width="10%">
            <apex:outputLink value="/{!list.theURL}">Click Here</apex:outputLink>
         </apex:column>
      </apex:dataTable>
   </apex:pageBlockSection>
   <apex:pageBlockSection Id="button_s">
       <apex:outputText value="{!strResponse}" />
       <br/>
   </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

My problem is that I woulk like for the "apex:commandButton" to go away, and just pass the "CustId"
to the controller from the VF page, and have the page render with the data from the HTTP callout directly.

All the examples I've seen seem to point to a rerender working under the pretext of re-querying
data once the datatable data is filled, but this obviously is a different case becayuse I'm
getting my data from an external API.

 

Is this possible?   I've tried putting the"getParameters()" call inside the constructor, but that didn't help.


Any help is appreciated.