I initialize the list at the beginning of the code. In one of the methods, I add values to it. In another method, the list is already empty. But I need these values in the second method. How to save them to get after?
public static List<String> listsIds = new List<String>();
@AuraEnabled
public static List<Object> getLists(){
//If I initialize the list here, nothing will change: "listsIds" will be null
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('myEndpointIsHere');
request.setMethod('GET');
HttpResponse response = http.send(request);
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
List<Object> lists = (List<Object>) results.get('lists');
List<String> listsNames = new List<String>();
for(Object oneList : lists){
String listInText = String.valueOf(oneList);
String listName = listInText.substringBetween('name=', '}');
String listId = listInText.substringBetween('id=', ',');
listsNames.add(listName);
//Here I added the values:
listsIds.add(listId);
}
return listsNames;
}
@AuraEnabled
public static void testIt(){
//Empty List:
System.debug(listsIds);
}