+ Start a Discussion
SFineSFine 

Global Class Issues

Hello, I'm trying to set up something so that when users select from a list of accounts that they would be brought over to a VF page, where they'll get exported into a spread sheet.

 

This mostly works, but I'm having a issue with transferring the ids from one page to the other. I've tried using a global variable and while I can populate it, it doesn't seem to carry over. Any ideas?

 

Global Class

 

global class Configero_DupeIDs {
 
 public static Boolean Ready = false;
 global static List<ID> dupeIds=new List<ID>();
 
  public static void setDupeIDs(List<ID> d){
  dupeids=d;
 }
 public static List<ID> getDupeIDs(){
  return dupeids;
 }
 
 public static void setReady(boolean r){
  ready=r;
 }
 public static boolean getReady(){
  return ready;
 }
 
 public static testMethod void testSkipTriggers(){
    list<id> ids=new list<id>();
    list <account> aids=[select id from account limit 10];
    for(account a:aids)
        ids.add(a.id);
    //SkipTriggers.dupeIds=ids;
    
        Configero_DupeIDs.setDupeIds(ids);
    

List<ID> getb;
      getb=  Configero_DupeIDs.getDupeIds();
    
    getb=Configero_DupeIDs.DupeIds;
 }
 
}

 Export method (This seems to work)

 public void Export(){
     Configero_DupeIDS.dupeids=new List<ID>();
     List<ID> dids=new List<ID>();
     System.debug('withdupelist '+withdupelist);
     for(DupeWrapper wd:withdupelist)
     {
         
     System.debug('accwrap '+wd.dupelist);
         for(AccountWrapper aw:wd.dupelist)
         {
             system.debug('aw ' +aw);
             if(aw.selected)
             {   dids.add(aw.acc.id);
             }
         }
     }
     System.debug('Dids '+dids);
     Configero_DupeIDS.setDupeids(dids);
     System.debug('Configero_DupeIDs.dupeids '+Configero_DupeIDs.dupeids);
 }

 Retrieving the ids method on another page/controller

public with sharing class DuplicationController {

    public DuplicationController(ApexPages.StandardSetController controller) {
        init();
    }


    public List<Account> DupeList { get; set; }
    
    public DuplicationController()
    {
        init();
    }
    
    public void init(){
    
        system.debug('Dupeids '+configero_dupeids.getdupeids());
        List <ID> dids=configero_dupeids.getdupeids();
        DupeList=[select id from Account where id in: dids];
        
        
    }
}

 

spraetzspraetz

Global variables will not be stored from one action to a separate page load. 

 

When the second page is loading, that receives its own context (set of limits, variable initialization, etc)

 

What you can do is save the IDs to a query string parameter and take them from there on the second page (ie, go to www.foo.com?ids=1,2,3,4,5,56,6,7,8,8,8,7)

 

or you can save the list of IDs to a custom object/custom setting and retrive it from the data base when loading the second page (ie: go to www.foo.com?objectId=2323232)