+ Start a Discussion
Michael MMichael M 

Create VF page from HTML callout response

I'm trying to generate a VF page with HTML that I get in my http callout response. What am I doing wrong? I am seeing this problem:
"Unknown constructor: 'SeekExension.SeekExtension()'

VF page:
<apex:page  controller="SeekExtension" contenttype="html" lightningStylesheets="true">
    <slds/>
 <apex:outputtext value="{!htmlString}" escape="false"/>
</apex:page>

Controller:
public class SeekExtension {
  public final Lead referral;
    public string respbody;

        Public SeekExtension(ApexPages.StandardController stdController){
      //  this.referral = (Lead)stdController.getRecord();
            referral =[Select Id, Name from Lead where Id = :ApexPages.currentPage().getParameters().get('id')];   
         
 }
    
    @future(callout = true)
 public static void  makePostCallout(id refId) { 
     string reqbody;
    String htmlString;
      
   Lead ref =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id = :refId]; 

     StaticResource r =[Select Id,Body from StaticResource where Name='Seek_Callout_Body' limit 1];
      reqBody=r.body.toString();

       HttpRequest req = new HttpRequest();
          // req.setHeader('Content-Length','0');
                req.setHeader('Content-Type','text/xml');
                req.setMethod('POST');
                req.setBody(reqBody);
                req.setEndpoint('callout:Seek');
                req.setTimeout(2 * 60 * 1000);
    system.debug('FULL REQUEST: ' + req);
           system.debug('BODY: '+ req.getBody());

         Http http = new Http();
           HttpResponse response = http.send(req);
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }
  
 htmlString =  response.getBody().substringAfter('~~~');
           system.debug(htmlString);
     
     XMLparse(response.getBody());
     
     // generatePdf(ref.id);

      //  return null;
    }        
Best Answer chosen by Michael M
David Zhu 🔥David Zhu 🔥
It seems you are using custom controller in VF page. But the constructor of class SeekExtension is for controller extension.
I would suggest you create a new constructor if the same class will be used as controller extension.

Public SeekExtension(){
...........
}


or remove parameter from constructor if the class is not used as a extension.

Public SeekExtension(ApexPages.StandardController stdController){

All Answers

David Zhu 🔥David Zhu 🔥
It seems you are using custom controller in VF page. But the constructor of class SeekExtension is for controller extension.
I would suggest you create a new constructor if the same class will be used as controller extension.

Public SeekExtension(){
...........
}


or remove parameter from constructor if the class is not used as a extension.

Public SeekExtension(ApexPages.StandardController stdController){
This was selected as the best answer
Michael MMichael M
Thanks, David. That got rid of the error message and let me save the page. Now I'm having issue that the VF page is not populating with any data. Any idea what the problem is/ if the problem is with my code?

Trigger:
trigger  ReferralCreateContact on Lead (after insert, after update) {
    for (lead l : Trigger.new){
        if (trigger.isinsert){
        SeekExtension.SeekExtension(l.id);
        }   }}

Class:
public class SeekExtension {
  public final Lead referral;
  //  public string htmlString {get; set;}
 
   @future(callout = true)
   Public static  void SeekExtension(id refId){

    String reqbody;
    String htmlString;
      
   Lead ref =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id = :refId]; 

     StaticResource r =[Select Id,Body from StaticResource where Name='Seek_Callout_Body' limit 1];
      reqBody=r.body.toString();

       HttpRequest req = new HttpRequest();
                req.setHeader('Content-Type','text/xml');
                req.setMethod('POST');
                req.setBody(reqBody);
                req.setEndpoint('callout:Seek');
                req.setTimeout(2 * 60 * 1000);
    system.debug('FULL REQUEST: ' + req);
           system.debug('BODY: '+ req.getBody());

         Http http = new Http();
           HttpResponse response = http.send(req);
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }
  
 htmlString =  response.getBody().substringAfter('~~~');
           system.debug(htmlString);
   generatePdf(ref.id);

      //  return null;
    }        

public static void generatePdf(Id leadId){
     
     PageReference ref = Page.SeekPage;
        ref.getParameters().put('id',LeadId);
        system.debug('ref1' + ref);
        
        Blob b;
     
if(Test.isRunningTest()) { 
  b = blob.valueOf('Unit.Test');
} else {
  b = ref.getContent();
}
     //   Blob b = ref.getContent();
        system.debug('ref' + ref);
        
        ContentVersion cv = new ContentVersion();
        cv.versionData = b;
        cv.title = 'SeekPage';
        cv.PathOnClient = 'SeekPage.pdf';
        insert cv;
        system.debug('cv' + cv);
        
        ContentVersion Content = [SELECT id, ContentDocumentId FROM ContentVersion where Id = :cv.Id];
        ContentDocumentLink contentlink=new ContentDocumentLink();
        contentlink.LinkedEntityId=LeadId;
        contentlink.ShareType= 'V';
        contentlink.ContentDocumentId= Content.ContentDocumentId;
        insert contentlink;
    
    }

}

Page:
<apex:page  controller="SeekExtension" contenttype="html"  lightningStylesheets="true">
    <slds/>

 <apex:outputtext value="{!htmlString}" escape="false"/>

</apex:page>