1

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?

1
  • Contact standard controller does not have an attribute called an 'amount'. Create an getter method in the extension and use it as a variable in pageblock table or some other structure where you would need the value...Might be a wrapper class in the extension will be helpful Commented Feb 11, 2014 at 10:47

1 Answer 1

4

Declare your variable as -

 transient global String amount {get; set;}
OR 
transient public String amount {get; set;}

By default, a method or variable is visible only to the Apex code within the defining class. If you do not specify an access modifier, the method or variable is private.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.