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
vignesh balasubramanian 14vignesh balasubramanian 14 

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
Amit Chaudhary 8Amit Chaudhary 8
Please try like below

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
John Pipkin 14John Pipkin 14
Vignesh, 

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.