I am trying to pass value from a map into a string set but get the error: variable does not exist: NewToolsMap in my execute method. I tried to make my map public but this does not seem to work. How can i solve this?

global class NewToolsTaskHandler extends psb_tsr.ScheduledTaskHandler{

    private static final Integer BATCH_SIZE;
    {   //load config
        BATCH_SIZE = FixConfigRepository.cfg_Fix.Batch_Size_SO_Task_Handler__c.intValue();

    global NewToolsTaskHandler(){
    MAP<Id, Stock_Product__c> NewToolsMap = new Map<Id, Stock_Product__c>();
    global override Iterable<psb_tsr.ITaskAction> DoInitialize(psb_tsr.IInitializeCommand initCommand){
        MAP<Id, Stock_Product__c> NewToolsMap = new Map<Id, Stock_Product__c>( [  SELECT  Id, Article_Code__c
                                                                                        FROM    Stock_Product__c 
        system.debug('NewToolsTaskHandler|NewToolsMap: ' + NewToolsMap);
        Set<Id> spIds = new Set<id>();
        List<NewToolsTaskAction> actions = new List<NewToolsTaskAction>();

        for(id NewToolsId : NewToolsMap.keySet()){
            if(spIds.size() == 10){
                actions.add(new NewToolsTaskAction(spIds));
                spIds = new Set<Id>();

        if(!spIds.isEmpty()) {
            actions.add(new NewToolsTaskAction(spIds));
        return (List<psb_tsr.ITaskAction>) actions;
    global class NewToolsTaskAction implements psb_tsr.ITaskAction{
        private Set<Id> spIdsToProcess;

        public NewToolsTaskAction(Set<Id> spIds){
            spIdsToProcess = spIds;

        public void Execute(){
            Utils.log('spIdsToProcess: ' + spIdsToProcess);
            Set<string> spArtcodeSet = new Set<string>(); 
            for(integer x=0; x<spIdsToProcess.size();x++){

There's a couple problems here.

First, you've declared NewToolsMap as an instance variable of NewToolsTaskHandler, but you've then shadowed it with a local declaration inside the DoInitialize() method, so your instance variable will never be initialized beyond the empty Map it starts with.

Second, the inner class NewToolsTaskAction does not have access to its enclosing class's instance variables, so it cannot see NewToolsMap in either place it is declared. If you want that class to have access to this data, you need to pass it as a parameter to the NewToolsTaskAction constructor, and store it as an instance variable in that class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.