There Can Be Only One

PHOTO EMBED

Tue Nov 09 2021 23:34:05 GMT+0000 (Coordinated Universal Time)

Saved by @yinmaster #apex #salesforce #static #keywords #class

Map<String,String> theOne = new Map<String,String>();
Map<String,String> theTwo = new Map<String,String>();

theOne.put('task', 'Active');
theOne.put('task2', 'Inactive');
theOne.put('task3', 'Inactive');
theOne.put('task4', 'Inactive');

theTwo.put('task', 'Active');
theTwo.put('task2', 'Inactive');
theTwo.put('task3', 'Inactive');
theTwo.put('task4', 'Inactive');

void toggleActive(String taskName, Map<String,String> taskMap){
    taskMap.put(taskName, 'Active'); 
    for(String key : taskMap.keySet()){
        if(key != taskName){
       	 taskMap.put(key, 'Inactive');
        }
    }
}

toggleActive('task3', theTwo);

System.debug(theOne);
System.debug(theTwo);
content_copyCOPY