I have two methods 1) getSiteIds and 2) fetchSession.

In the first method getSideIds I want to populate an empty Map<String,String> siteIds = new Map<String,String(); with (name, id):

Map<String,String> siteIds = new Map<String,String();
for (Object dataIte : data) {
    Map<String, Object> dataMapIte = (Map<String, Object>) dataIte;
    String id = (String) dataMapIte.get('id');
    Map<String, Object> attributes = (Map<String, Object>) dataMapIte.get('attributes');
    String name = (String) attributes.get('name');
    siteMap.put(name, id);

NOTE: I declared the siteIds map outside of the method with public accessibility, so it should be available to other methods?

In the second method fetchSession I want to search for id of a site and I provide the name:

Data data = new Data();
data.website_id = siteMap.get(selectedSiteName); 

I wrote system.debug(data.website_id); just so I test this but I get null value: Link.

Any suggestions on how can I set the values of the siteIds with the first method and then use the map in the second method?

  • 2
    Can you add both the methods? Also, ensure you are not declaring the map within the method. Also looking at the screen shot seems like, you are getting the value from the map even before adding it. Commented Aug 30, 2022 at 12:59
  • I've edited my question and added the methods. Also as I said before, I declared the map outside of the methods.
    – Stojchesky
    Commented Aug 30, 2022 at 13:04

1 Answer 1


It looks like you're trying to call these methods from an Aura or LWC component. Presumably, these are two separate calls made by the component. Because the entire Lightning framework is a "stateless" environment, your static variable won't be remembered between the calls to getSiteIds and fetchSessions. Realistically, fetchSessions would need to call getSiteIds first, or you'd have to have your JavaScript send the appropriate data from the controller.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .