function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jayaramu T 9Jayaramu T 9 

please find the below code i am getting error at line 14 "CMileS" is a for loop local variable. please suggest me how to rectify this? highlited as bold

 
List<CaseMilestone> lp_setmstones = new List<CaseMilestone>();

	Set<Id> mstoneIDs = new Set<Id> ();
	LIST<CaseMilestone> setmstones;
    for (CaseMilestoneSetting__c CMileS : CMileSs){
        mstoneIDs.add(CMileS.MilestoneID__c);      
    }
	// Find all CaseMilestones matching our criteria in our caselist
	if(system.test.isRunningTest()) {
		setmstones = Database.query('Select ID,MilestoneTypeID,CompletionDate FROM CaseMilestone WHERE CaseID IN:caselist AND MilestoneTypeID IN :mstoneIDs AND CompletionDate=NULL');
	}  
	else {
		setmstones = Database.query('Select ID,MilestoneTypeID,CompletionDate FROM CaseMilestone WHERE '+
                                                        CMileS.CaseCriteria__c+
                                                        'AND CaseID IN:caselist AND MilestoneTypeID IN :mstoneIDs AND CompletionDate=NULL');
	}
	
	// Update the CompletionDate for each CaseMilesone
	for (CaseMilestone updatemstone : setmstones){
		updatemstone.CompletionDate= Datetime.now();
	}
	// Execute the update for all the Milestones in this set
	lp_setmstones.addAll(setmstones);
Steven NsubugaSteven Nsubuga
CMileS.CaseCriteria__c should be removed from the query because it is not even being checked against anything in the SOQL query.
sfdc freshersfdc fresher
CMileS is just local variable for that loop only,so we cant use it outside.in order to rectify it write thoese if and else conditions inside the for loop