I've been wondering about this alot. I have a VF page that has a StandardController for Contact and a custom extension that handles an external webservice call. This extension class contains a string value that the web service call sets and then I need to pass that value to the VF page for display. This value is not bound to any field in SF but is rather just a string value. I'm trying to use actionFunction to do this, since it seems easier than using JS Remoting (my JS callback function skill level is not high)
VF Page:
<apex:page showHeader="false" sidebar="false" standardController="Contact" extensions="CallStatus">
<apex:form >
<apex:actionFunction name="gomob" action="{!GetCallStatus}" reRender="amount"/>
<div id="black">
<apex:outputpanel id="amount">
<apex:outputText value="Get Status!: {!amount}"/>
<apex:actionSupport event="onclick"
action="{! GetCallStatus}"
rerender="amount" status="whileStatus"/>
</apex:outputpanel>
<apex:actionStatus id="whileStatus"
startText=" (fetching...)"
stopText=" (done)"/>
</div>
</apex:form>
</apex:page>
My extension class:
global class CallStatus {
private final ApexPages.StandardController controller;
public WS_GoMobileStatus(ApexPages.StandardController controller){
this.controller = controller;
}
global String kId { get; set; }
transient String amount {get; set;}
Contact con;
public CallStatus(){
}
Public String GetCallStatus(){
String conId = ApexPages.currentPage().getParameters().get('Id');
con = [SELECT Id,kid__c from Contact where Id =:conId LIMIT 1];
ktId = con.kid__c;
String endp = 'ENDPOINT_URL?action=GetCallStatus&kid=';
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setHeader('Content-Type','application/json; charset=utf-8');
req.setHeader('User-Agent', 'force.com');
req.setEndpoint(endp+=ktId);
Http http = new Http();
System.HTTPResponse res = new System.HTTPResponse();
try {
//Execute web service call here
res = http.send(req);
//Helpful debug messages
System.debug(res.toString());
System.debug('STATUS:'+res.getStatus());
System.debug('STATUS_CODE:'+res.getStatusCode());
} catch(System.CalloutException e) {
//Exception handling goes here....
}
amount = res.getBody();
return amount;
}
}
Is my use of the transient keyword wrong here? When I refer the {!amount} in the VF page, I get the error
Error: Unknown property 'ContactStandardController.amount
Is t not possible to have the extension class return the String value to the VF page?