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
WitteWitte 

auto update inputfield

Hi,

 

Im new with Salesforce and with coding of APEX.

 

Can anyone help me getting started with how to auto update an inputfield?

 

Lets say i have a made a httprequest.

 

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

Now i want the data to be placed in a inputfield. But i dont know where to start.

sfdcfoxsfdcfox

You need an event to act as the catalyst for your code being invoked. This can be the constructor of the page or an action attribute. Then, assign the value as normal during your action event, and it will update the inputfield. For example:

 

 

// Controller
public with sharing class TestController {
  public string Country { get; set; }
  public string ExchangeRate { get; set; }

  public void updateExchangeRate() {
    Http gate = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://www.yoursite.com/path/to/service/');
    req.setMethod('get');
    HttpResponse res = gate.send(req);
    ExchangeRate = res.getBody();
  }
}

// page
<apex:page controller="TestController">
 <apex:form id="theform">
  <apex:pageBlock>
   <apex:pageBlockSection>
    <apex:inputText value="{!Country}">
      <apex:actionSupport event="onchange" action="{!updateExchangeRate}" reRender="theForm"/>
    </apex:inputText>
    <apex:inputText value="{!ExchangeRate}"/>
   </apex:pageBlockSection>
  </apex:pageBlock>
 </apex:form>
</apex:page>

 

Of course, it would be slightly more complex (maybe you want a dropdown, or maybe it runs off of an object, etc), but the logic will be essentially the same. Attach an actionSupport, or use a commandButton, commandLink, or actionFunction to cause your code to be executed. Assign the results to a binding variable, and your results will automatically appear when the page refreshes.

WitteWitte

Thank you sfdcfox for the repsonse.

 

But its not quit what i want to achieve

 

When i`m creating an instace of the object i`ve created

i want in one of the input boxes automatically placed value. its a propertie of the object. The value placed in the inputbox is the value captured from the http request.

  

    HttpRequest req = new HttpRequest();
    req.setEndpoint('url');
    req.setMethod('get');
    HttpResponse res = gate.send(req);
    ExchangeRate = res.getBody();

Therefor i can use this code. I dont want to make a new webpage. The controller is therefor also in mij vision not needed.

 

Do you or anyone can help me with this. Thnx in front