Skip to main content
added 612 characters in body
Source Link
Alexis MASSON
  • 1k
  • 4
  • 21
  • 40

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.

EDIT : so now, maybe I should open a new topic because it has to do with it but not about the @future context specifically (I can do it if asked to)

As I understood your answer, I could transfer some sobjects from one Method to another one by doing something like

Class testMap {
var A;

meth1(param A) {
    // do something about A
    // don't return A, but i's affected because of referencing passage
}

meth2(paramA) {
    // use A with the value it has after metho 1 is Called
}

}

But I'm unable to do it ... Am I missing something ?

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.

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.

EDIT : so now, maybe I should open a new topic because it has to do with it but not about the @future context specifically (I can do it if asked to)

As I understood your answer, I could transfer some sobjects from one Method to another one by doing something like

Class testMap {
var A;

meth1(param A) {
    // do something about A
    // don't return A, but i's affected because of referencing passage
}

meth2(paramA) {
    // use A with the value it has after metho 1 is Called
}

}

But I'm unable to do it ... Am I missing something ?

Source Link
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.