Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a class

public class Sample {
  public static Map<String,List<String>> flowMap;

       public static List<String> getFlowList(){
        flowMap = new Map<String,List<String>>();
        MetadataService.MetadataPort service = createService();
        MetadataService.ListMetadataQuery query = new MetadataService.ListMetadataQuery();
        query.Type_x = 'Flow';
        MetadataService.FileProperties[] lmr = service.listMetadata(
            new MetadataService.ListMetadataQuery[] {query}, 30);
        for(MetadataService.FileProperties properties:lmr)
         {List<String> ff = flowMap.get(properties.fullName.split('-')[0]);
         if(ff == null)
         ff = new List<String>();

        flowList = new List<String>(flowMap.keySet());
          return flowList;

First in my page, I called getFlowList. After that, I clicked a button in which flowMap is used. In flowMap, value it is returning is null, but in this function, it's assigned flowMap. Why is it returning null?

share|improve this question

Static variables are implicitly transient, which means their state is not stored in the view state (meaning each transaction starts all static variables as null). Use an apex:actionFunction if you expect to be able to interact with the view state, and make sure your variable is not static.

share|improve this answer
They won't then be able to access the map since it would be an instance variable, I don't think you can maintain any state on a Remoting class since they are stateless....if you want to persist data, don't you have to use viewstate a la normal VF/Controllers? – Phil Hawthorn Jul 9 '14 at 14:33
@PhilHawthorn Of course, you're right. I edited the answer to be more appropriate for this case. – sfdcfox Jul 9 '14 at 14:35

See the following discussion about static variables in controllers. In short, static variables are only static within the scope of a single request, not multiple requests.

If you want to preserve that state, you'll have to store the result of your remote method somewhere in your VF page. You can then pass it through to the server when the user clicks the button.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.