+ Start a Discussion
SF Beginner 2019SF Beginner 2019 

Too Many soql is there a way to optimize this more?

is there a way we can optimize these more?
public static void checkOpenActivities(List<Case> caseList,Map<Id,Case> caseOldMap) {
       List<Case> casedList = New List<Case>();
       List<Task> tskList = new List<Task>();
       integer openActivitiesCount = 0;

       Set<Id> cId = new Set<Id>();
       for(Case cs : caseList) {
       tskList = [SELECT Id,Status FROM Task Where Status != 'Completed' AND WhatId IN :cId];
        for(Case csNew : caseList) {
            if(tskList.size() != 0 && (csNew.Type__c == 'Question' || csNew.Type__c == 'Information') && csNew.Status == 'Closed') {
                csNew.addError('Can not be closed this');

Pradeep LandgePradeep Landge
You need to reduce SOQL from other related methods or try to write a future method instead of normal methods.

If this helps you please mark it as solved.