I'm successfully calling the GetRestID method in this controller on my VisualForce Page and see the correct response from the getParameters() method from my SOQL query. The problem is trying to pass 'RestID' to my GET method. I believe the callout is happening before getParameters() returns the ID value of the current Account page.
What is the correct way to pass the active Account ID to my GET method?
Controller:
public with sharing class extensionTest {
private final Account acct;
public String restID;
public RSAPI.responseResource ConsoleWrapperList {get; set;}
public extensionTest(ApexPages.StandardController controller) {
this.acct = (Account)controller.getRecord();
}
public String getGetRestID (){
restID = [Select someID from account where id = :System.currentPagereference().getParameters().get('Id')].someID;
return restID;
}
public wrapper.responseResource getperformCallout(){
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('https://blahblah/' + getGetRestID());
req.setMethod('GET');
req.setHeader('Authorization','da932512800');
res = http.send(req);
if(res.getStatusCode() == 200 && res.getBody() != null){
ConsoleWrapperList = (wrapper.responseResource)json.deserialize(res.getBody(),wrapper.responseResource.class);
}
return ConsoleWrapperList;
}
}
Apex Page:
<apex:page standardController="Account" extensions="extensionTest">
{!GetRestID} //The value to pass to GET method
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!performCallout}" var="wrap">
<apex:column value="{!wrap.someId}"/>
<apex:column value="{!wrap.someName}"/>
<apex:column value="{!wrap.someAmount}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
System.debug(getGetRestID())
ingetperformCallout()
? Also, what are you actually seeing? An error? The Debug log should give you a lot of info about the callout - the URL it's trying to reach, the response etc.