+ Start a Discussion
SF Beginner 2019SF Beginner 2019 

task size is 0 not working

I tried to make an else statement but it seems i doesn't indentify when it has a size of 0
 
List<Task> taskCompletedOrInvalidPhone = [SELECT Id, whatid, CallCustom__c, RecordtypeId 
                                                  FROM Task 
                                                  WHERE Whatid IN :forWhatID 
                                                  AND CallCustom__c = 'Completed' AND WhatID != null];
        for(Task tsk : taskCompletedOrInvalidPhone){
            if(accountIdToListTaskCompletedMap.containsKey(tsk.WhatId)){
                accountIdToListTaskCompletedMap.get(tsk.WhatId).add(tsk);
            }
            else{
                accountIdToListTaskCompletedMap.put(tsk.WhatId, new List<Task>{tsk});
            }
        }


for(Id acctId : forWhatID){
            if(accountIdToListTaskCompletedMap.containsKey(acctId)){
                if(accountIdToListTaskCompletedMap.get(acctId).size() >0){
                    if(accountIdToListDepMap.containsKey(acctId)){
                        for(Dependent__c covMem : accountIdToListDepMap.get(acctId)){
                            if(coverageIdToListDepMap.containsKey(covMem.Coverage__c)){
                                for(Dependent__c depMem2 : coverageIdToListDepMap.get(covMem.Coverage__c)){
                                    accountsToUpdate.put(depMem2.Account__c, new Account(Id=depMem2.Account__c, Good__c=true, Verygood__c=true));
                                }
                            }
                        } 
                    } 
                }
            }
			else{
			if(accountIdToListTaskCompletedMap.containsKey(acctId)){
                if(accountIdToListTaskCompletedMap.get(acctId).size() == 0){
                    if(accountIdToListDepMap.containsKey(acctId)){
                        for(Dependent__c covMem : accountIdToListDepMap.get(acctId)){
                            if(coverageIdToListDepMap.containsKey(covMem.Coverage__c)){
                                for(Dependent__c depMem2 : coverageIdToListDepMap.get(covMem.Coverage__c)){
                                    accountsToUpdate.put(depMem2.Account__c, new Account(Id=depMem2.Account__c, Good__c=false, Verygood__c=false));
                                }
                            }
                        } 
                    } 
                }
            }
			}

 
Deepali KulshresthaDeepali Kulshrestha
Hi,

Try the following code it may be helpful for you:
List<Task> taskCompletedOrInvalidPhone = [SELECT Id, whatid, CallCustom__c, RecordtypeId 
                                                  FROM Task 
                                                  WHERE Whatid IN :forWhatID 
                                                  AND CallCustom__c = 'Completed' AND WhatID != null];
        for(Task tsk : taskCompletedOrInvalidPhone){
            if(accountIdToListTaskCompletedMap.containsKey(tsk.WhatId)){
                accountIdToListTaskCompletedMap.get(tsk.WhatId).add(tsk);
            }
            else{
                accountIdToListTaskCompletedMap.put(tsk.WhatId, new List<Task>{tsk});
            }
        }


for(Id acctId : forWhatID){
            if(accountIdToListTaskCompletedMap.containsKey(acctId)){
                if(accountIdToListTaskCompletedMap.get(acctId).size() >0){
                    if(accountIdToListDepMap.containsKey(acctId)){
                        for(Dependent__c covMem : accountIdToListDepMap.get(acctId)){
                            if(coverageIdToListDepMap.containsKey(covMem.Coverage__c)){
                                for(Dependent__c depMem2 : coverageIdToListDepMap.get(covMem.Coverage__c)){
                                    accountsToUpdate.put(depMem2.Account__c, new Account(Id=depMem2.Account__c, Good__c=true, Verygood__c=true));
                                }
                            }
                        } 
                    } 
                }
                else if(accountIdToListTaskCompletedMap.get(acctId).size() == 0){
                    if(accountIdToListDepMap.containsKey(acctId)){
                        for(Dependent__c covMem : accountIdToListDepMap.get(acctId)){
                            if(coverageIdToListDepMap.containsKey(covMem.Coverage__c)){
                                for(Dependent__c depMem2 : coverageIdToListDepMap.get(covMem.Coverage__c)){
                                    accountsToUpdate.put(depMem2.Account__c, new Account(Id=depMem2.Account__c, Good__c=false, Verygood__c=false));
                                }
                            }
                        } 
                    } 
                }
            }
            }

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha