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
karthic sankar 9karthic sankar 9 

Please help in resolving below error

HI Experts,

Can someone please tell me how to resolve this issue.

public void UpdateTheValue(List<QAAM_Weekly_Planner__c> weekValues)
    {
       List<QAAM_Weekly_Planner__c> updateWeekValuetotal = new List<QAAM_Weekly_Planner__c>(); 
        for(QAAM_Weekly_Planner__c plan : weekValues)
        {
            List<QAAM_Weekly_Planner__c> updateWeekValue = [select Pre_Vet_Reviews__c, id from QAAM_Weekly_Planner__c where id =:plan.id];
            updateWeekValue.Pre_Vet_Reviews__c = 5.0; 
            updateWeekValuetotal.add(updateWeekValue);
        }
        update updateWeekValuetotal;
    }

Error:
Variable does not exist: Pre_Vet_Reviews__c

Reagrds
Karthic Sankar V P
WEN JIEWEN JIE
Hi,

I did check the details. But please don't add any SOQL in your loop. And then recheck your logic.

Thank you!
karthic sankar 9karthic sankar 9
In this case, I dont have option to add SOQL inside my loop.. Request you to kindly assist.
 
WEN JIEWEN JIE
Hi Karthic,

FYI.
Actually, I don't know the purpose for this method (UpdateTheValue). You pass a list in this method, and then you update one field(Pre_Vet_Reviews__c) from this list right ?  Why don't you query this fields in this list before?
 
public void UpdateTheValue(List<QAAM_Weekly_Planner__c> weekValues)
    {
       List<QAAM_Weekly_Planner__c> updateWeekValuetotal = new List<QAAM_Weekly_Planner__c>(); 
	   Set<String> idSet = new Set<String>();
		for(QAAM_Weekly_Planner__c plan : weekValues)
        {
           idSet.add(plan.id); // Get a set which contians all ID from weekValues
        }
		
		List<QAAM_Weekly_Planner__c> updateWeekValue = [select Pre_Vet_Reviews__c, id from QAAM_Weekly_Planner__c where in : idSet]; // Get your result
		
		for(QAAM_Weekly_Planner__c qwp : updateWeekValue){
			qwp.Pre_Vet_Reviews__c = 5.0;
			
		}
		update updateWeekValue;
    }
karthic sankar 9karthic sankar 9
Infact i even get values in it.

 public void UpdateTheValue(List<QAAM_Weekly_Planner__c> weekValues)
    {
       List<QAAM_Weekly_Planner__c> updateWeekValuetotal = new List<QAAM_Weekly_Planner__c>(); 
        for(QAAM_Weekly_Planner__c plan : weekValues)
        {
            List<QAAM_Weekly_Planner__c> updateWeekValue = [select Pre_Vet_Reviews__c, id from QAAM_Weekly_Planner__c where id =:plan.id];
            system.debug(updateWeekValue);
        }
        update updateWeekValuetotal;
    }

User-added image
WEN JIEWEN JIE
I mean this obj list --- weekValues.  As your code, the function parmarter is  a list of QAAM_Weekly_Planner__c obj. Then you loop this list to get the id. Then you query QAAM_Weekly_Planner__c obj again by this ID. So why don't you add Pre_Vet_Reviews__c in your weekValues ?