Skip to main content
1 of 2
Alexis MASSON
  • 1k
  • 4
  • 21
  • 40

How could I get values from a global declared map, inside a @future method?

I'm facing an issue of accessing objects, That is the first time I'm trying to use Global variables on APEX ;

I got a @future main method that calls two methods, In the first method I would like to fill values for a Map I will use on the second Method, without returning it (already returning another Map) ;

My idea was to use a variable declared as global on the Class level, but it seems impossible because of the future context... How could I do ? Returning the two maps, from the first method ?

I found that topic that match the context of my issue, no real answering however..

Class and global declared Map :

global with sharing class AP01_CrecheSiteWeb {
    global Map<Id, List<Account>> mapIdContratToFinalListCreches {get; set;}
    ...

The @futur method :

    @future
    public static void updateCrecheSiteWeb(List<Id> listCZDTIds) {

    // Call first method - I want it to set another map in order to access it in the 2nd method !
    Map<Id, List<Account>> mapIdContratToListAssociatedCreches = getMapContractToCreches(listCZDTIds);

    try {
        // Call second method, that should use the map set in the 1st method, and of course the map returned by the 1st method
        getMapContractToCrechesSiteWeb(mapIdContratToListAssociatedCreches);
    } catch (Exception ex){
        System.debug('--AP01_CrecheSiteWeb EXCEPTION --' + ex.getMessage());
    }
}

First method (parts of) :

public Map<Id, List<Account>> getMapContractToCreches(List<Id> listCZDTIds) {
     
      [...] 
     // I want to do something like this :
    
    Map<Id, List<Account>> getGlobalMap = this.mapIdContratToFinalListCreches;

     [...]

     return anotherMap;
 }

And the 2nd method would do the same, get the global Map, use it, clear it.

Alexis MASSON
  • 1k
  • 4
  • 21
  • 40