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
shashi kanaparthishashi kanaparthi 

Displaying a web service response to the user before page navigation

Hi,

I am trying to display the web service response to the end user before page navigation. But its not working. I am retrieving the body in the public String xmlContent{get;set;} in the below class and in the VF Page i am refrencing int the outputtext:-

public class Quote_To_CW_Test {
    
    public List<Quote> Qlist{get;set;}
    
    public String xmlContent{get;set;}
    
    public Quote_To_CW_Test() {
    
        qid=[Select Id from Quote where Id=:ApexPages.currentPage().getParameters().get('quoteId')].id;
        
        Qlist=[Select Conversion_Status__c,Id,IsSyncing from Quote where Id=:ApexPages.currentPage().getParameters().get('quoteId')];

system.debug('////////////' +Qlist[0].Conversion_status__c);
    }
    
 private final Quote q;string qid;
          
public PageReference invokeMule(){
    

/*redirect user to another page*/


/*logic for web service call out here*/
if(Qlist[0].Conversion_Status__c!='Sent'){

String url;

url='https://xxxxxx:10000/QuoteToCW/' + Qlist[0].Id;

HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
req.setEndpoint(url);

//req.setHeader('Content-Type', 'application/x-www-form-urlencoded');  


// create the response object
HTTPResponse resp;

 resp = http.send(req);

 /*catch(System.CalloutException e) {
        System.debug('Callout error: '+ e);
        System.debug('**************' +resp.toString());
    }*/
 
String xmlContent=String.valueOf(resp.getBody());

System.debug('////////' +resp.getBody());


System.debug('+++++++++ XMLContent is'+ xmlContent);


system.debug('The request end point is ++++' + url);
 
req.setEndpoint(url);

}

  //disabl = true;

PageReference qPage= new PageReference('/' +qid);


apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Status of the response ' + xmlContent);
        apexpages.addmessage(msg);
        
        
        
    
return qPage;

}


/* Cancel to return to the previous page*/

public PageReference Cancel() {
    
PageReference qPage = new PageReference('/' +qid);
        
return qPage;
   
    }
}




VF Page:-

<apex:page controller="Quote_To_CW_Test" sidebar="false" id="page">

<apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" / >
 
  

<apex:form id="form">

<apex:outputText value="{!xmlContent}" />
  
  <apex:pageBlock id="pageblock">
  
    <style>
            body .bPageBlock .pbBody .red .pbSubheader{
                background-color:#c00000;
            }
            body .bPageBlock .pbBody .grey .pbSubheader{
                background-color:#c0c0c0;
            }
            body .bPageBlock .pbBody .grey .pbSubheader h3{
                color:#000;
            }
            
            {
         text-align:center;
}
            
           </style>
    
    
    <style type="text/css">

.wrapper {
         text-align:center;
}
</style>

  <script>
  
  
      
      function validateFunction(paramval,paramval1){
      
      if(paramval=='Sent'){
      
      alert('The quote has already been sent to CW. You cannot send this Quote to CW.This page will now redirect to the Quote Detail Page');
      
    return false;
      }
      
      
      if(paramval1=='false'){
      
      alert("Your Quote has not been synced. Please sync your quote before continuing");
      
     return false;
      
      }
                  
      }
          
</script>

<apex:actionStatus id="SaveButtonStatus">

<apex:facet name="stop">
       
  <apex:outputPanel styleClass="red" id="outputpanel">
  
  <apex:pageBlockSection title="Click on the Quote>CW button below to send the Quote to CW"  id="pbSection">
  
 <apex:pageMessages id="showmsg"/>
             <div align="center" draggable="false">                    
<apex:commandbutton onclick="validateFunction('{!Qlist[0].Conversion_Status__c}','{!Qlist[0].IsSyncing}')"
action="{!invokeMule}"  
styleclass="commandbutton" value="Quote>CW" status="SaveButtonStatus"
style="margin-left:800px;float:center;"
id="saveButtonId" 
rerender="showmsg"/> 
 
<apex:commandButton action="{!Cancel}" style="float:center;"
      value="Cancel" disabled="false" id="theCancelButton"/>
      
      </div>

       </apex:pageBlockSection>
           
          
   </apex:outputPanel>
  
  </apex:facet>
 
  <apex:facet name="start">
  
       <apex:outputPanel styleClass="red" rendered="{!Qlist[0].Conversion_Status__C!='Sent'}">
       <div align="center" draggable="false">
       <apex:pageBlockSection title="Your Quote is being sent to CW. You will be redirected back to the Quote screen">
       
      <apex:pageMessages id="showmsg"/>
        <apex:commandButton styleclass="commandbutton" 
        onclick="validateFunction('{!Qlist[0].Conversion_Status__c}','{!Qlist[0].IsSyncing}')"
        rendered="{!Qlist[0].Conversion_Status__C!='Sent'}"
        style="margin-left:800px;float:center;"
        value="Sending Quote to CW..." disabled="true"  rerender="showmsg"/>
         
          <apex:commandButton action="{!Cancel}" value="Cancel" disabled="true" id="theCancelButton" immediate="true"
         style="margin-left:1000px;float:center;"/>
         
        </apex:pageBlockSection>
        
         </div>
       </apex:outputPanel> 
      
      </apex:facet>
  
  </apex:actionStatus>
  
  </apex:pageBlock>
   </apex:form>
</apex:page>
Temoc MunozTemoc Munoz
Hi Shashi.

You won't be able to do this with Apex.

You can try using JavaScript (i.e. alert message) and redirect from there.
shashi kanaparthishashi kanaparthi
Hi,

The requirement is to disable the button after on click , hence i am using a vf page. 

i tried capturing the response in a string variable and passed that variable to a java script function in a vf page. But null value is being passed to java script alert. 

I checked the debug logs, the variable is getting the correct XML response.