1

So I have a list of Strings which is populated with Ids (in form of Strings) in the batchProcessSchedules() method. By reaching the limit (size) it will pass this list, together with another list and a single String to the @Future method. The other List (assetIds) is populated earlier in the code.

Everything seems to work, except that one list (schedulePack), when 'arriving' in the @Future method, is empty. It should not be empty, since I passed the populated list (toProcess) into the method.

There are some debug-statements already, to check the variables through the whole method. So I already checked, if the list toProcess is actually populated the moment before it gets passed to @Future. It contains all the String values it should before and after beeing passed to the future method. Just right after the @future method starts the equivalent list (schedulePack) in the @Future method is empty. Strangly it works for the other List (assetIds) and the single String (mode), they are not empty when the @Future method starts executing. I also tried switching the Lists on both sides: It is always the list toProcess that will end up empty in the @Future method.

I don't think this has to do with the Problem, but schedulesByRecordtype is a Datacollection of type Map<String,Map<String,Schedule__c>>.

From all I learned so far, this should work. Also it works with the second list. So I guess i am overseeing something. Maybe something that differs the list toProcess from the list assetIds.

Thanks!

private static String mode = 'noMode';
private static List<String> assetIds = new List<String>();
private static List<String> toProcess = new List<String>();

    private void batchProcessSchedules(Integer size) 
    {
       
        for(String sx : schedulesByRecordtype.get(mode).keySet())
        {
                 
            if ((schedulesByRecordtype.get(mode).keySet().size()+toProcess.size())<size)
            {
                break;   
            }

            //DEBUG
            System.debug('OBJECTID - Batchprocessor '+schedulesByRecordtype.get(mode).get(sx).Id);
            //DEBUG

            toProcess.add(schedulesByRecordtype.get(mode).get(sx).Id); 
            schedulesByRecordtype.get(mode).remove(sx);

            if(toProcess.size() == size)
            {   
                // DEBUGS
                System.debug('Future about to be called. Size: '+toProcess.size());
                         // Size as expected
                // DEBUGS

                ProcessSchedulesAsFuture(toProcess,mode,assetIds);

                // DEBUGS
                System.debug('After sendout | tP: '+toProcess.size()+' | SBR: '+schedulesByRecordtype.get(mode).keySet().size());
                         // Sizes as expected
                // DEBUGS               
                
                toProcess.clear();
            }
        }
        processSchedules(); 
    }



 @Future
    public static void ProcessSchedulesAsFuture(List<String> schedulePack, String recType, List<String> assIds)
    {
        futureMode = true;
        mode = recType;

        // DEBUGS
        System.debug('Future started. Mode: '+recType); 
                     // recType contains the expected value
        System.debug('Amount Schedule-Ids: '+schedulePack.size()); 
                    // schedulePack is empty | Size = 0
        System.debug('Amount Asset-Ids: '+assIds.size()); 
                   // assIds contains the expected amount of values        
        // DEBUGS

        objectName = 'Schedule__c';
        whereClause.clear();
        whereClause.add('Id IN :idCollection');
        idCollection.clear();
        idCollection.addAll(schedulePack);
        assetIds.addAll(assIds);


        setupScheduleMap();
        newSchedules = dynamicQuery();
        sortSchedules();
        processSchedules();
    }

1 Answer 1

0

So since I could not find a solution, that made it possible to pass the said List into the @Future methode, I went another way which made the code work. Though I am not really happy with it since it is just a workaround for the actual problem.

Here is what I did: I serialized the List toProcess into a String. Passed the String into the @Future method and then deserialized it back into a List. Now the Listcontent was also available in the @Future method. I only did this for the toProcess List, since passing the other List just worked fine.

I am still clueless why the contents of the List toProcess could not be passed into the @Future method.

You must log in to answer this question.

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