You need to sign in to do that
Don't have an account?

How to Display Static List<String> in VF page
Hi Everyone,
I want to display static List<String> in VF Page, give me solution for below problem,
Public static List<String> reslist{get;set;}
@future(callout=true)
public static void futuremethod(Decimal lat,Decimal lng)
{
reslist=new List<String>();
system.debug('future called');
HttpRequest req = new HttpRequest();
req.setEndPoint('https://developers.zomato.com/api/v2.1/geocode?lat='+lat+'&lon='+lng+'');
req.setMethod('GET');
req.setHeader('Accept', 'application/json');
req.setHeader('user-key', '806bc2fff09af32e5cf1ed4b9c11de5c');
Http http = new Http();
HttpResponse res;
if(!Test.isRunningTest())
{
String s='some text from response';
reslist.add(s);
}
}
VF page:
--------
<apex:page standardController="Account" extensions="ShowRestaurant_AC">
<apex:form >
<apex:pageBlock >
<apex:commandButton value="Show Restaurants" action="{!callfuture}"/>
<apex:pageBlockSection title="Contacts in Map">
<apex:map width="2000px" height="500px" mapType="roadmap" center="{!bstreet},{!bCity},{!bState}" zoomLevel="{!zoomvar}">
<apex:repeat value="{!reslist}" var="res">
<apex:mapMarker title="{!res}" position="{!res}"/>
</apex:repeat> /**********************HERE I CANNOT DISPLAY STATIC VARIABLE*************************
</apex:map>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I CANNOT DISPLAY reslit (STATIC LIST) IN VF PAGE.HOW TO DO THIS
I want to display static List<String> in VF Page, give me solution for below problem,
Public static List<String> reslist{get;set;}
@future(callout=true)
public static void futuremethod(Decimal lat,Decimal lng)
{
reslist=new List<String>();
system.debug('future called');
HttpRequest req = new HttpRequest();
req.setEndPoint('https://developers.zomato.com/api/v2.1/geocode?lat='+lat+'&lon='+lng+'');
req.setMethod('GET');
req.setHeader('Accept', 'application/json');
req.setHeader('user-key', '806bc2fff09af32e5cf1ed4b9c11de5c');
Http http = new Http();
HttpResponse res;
if(!Test.isRunningTest())
{
String s='some text from response';
reslist.add(s);
}
}
VF page:
--------
<apex:page standardController="Account" extensions="ShowRestaurant_AC">
<apex:form >
<apex:pageBlock >
<apex:commandButton value="Show Restaurants" action="{!callfuture}"/>
<apex:pageBlockSection title="Contacts in Map">
<apex:map width="2000px" height="500px" mapType="roadmap" center="{!bstreet},{!bCity},{!bState}" zoomLevel="{!zoomvar}">
<apex:repeat value="{!reslist}" var="res">
<apex:mapMarker title="{!res}" position="{!res}"/>
</apex:repeat> /**********************HERE I CANNOT DISPLAY STATIC VARIABLE*************************
</apex:map>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I CANNOT DISPLAY reslit (STATIC LIST) IN VF PAGE.HOW TO DO THIS
ShowRestaurant_AC.reslist = new List<String>();
You can use Mock Test class for same
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
Let us know if this will help you
Why does this list and method need to be static? There is no obvious benefit from what I see. Static variables do not get sent to the view state. Make this list an instance variable and move your controller method to an instance method as well. Otherwise, this will need to be javascript remoting and the javascript will have to handle the data. @future methods in visualforce controllers should typically only be used when you don't the need the information back from the webservice call. Since you do need that information, you should not use future.