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
TUSHAR KHORGADETUSHAR KHORGADE 

getting error in update field

System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

public with sharing class InvestmentController {
   
@AuraEnabled(cacheable=true)
public static List<HSA_Investment__c> fetchInvestment() {
List<HSA_Investment__c> invest = [SELECT Id,Name,Company_Sector__r.Name,Fund_Released_Date__c
FROM HSA_Investment__c];
System.debug('In the fetch ' +invest );
return invest;
}

@auraEnabled
public static void savePriceValue(List<Integer> InvestmentPrice){
System.debug('check me ' + InvestmentPrice);
    List<HSA_Investment__c> priceUpdate = new List<HSA_Investment__c>();
    for(Integer i=0; i<InvestmentPrice.size(); i++){
        HSA_Investment__c empCardObj = new  HSA_Investment__c();
        empCardObj.NAV__c= InvestmentPrice[i];
       
        priceUpdate.add(empCardObj);
        }
        system.debug('price updateddd'+ priceUpdate);
       
    update priceUpdate;
    //return priceUpdate;
}
}
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Tushar,

For any update you perform you need to mention the Id of the record. Or else system will not understand which record it should update. 

In the below line of code you are not adding the id of the record.
 
for(Integer i=0; i<InvestmentPrice.size(); i++){
        HSA_Investment__c empCardObj = new  HSA_Investment__c();
        empCardObj.NAV__c= InvestmentPrice[i];
       
        priceUpdate.add(empCardObj);
        }

Please mention the id of the record and perform the operation.

If this solution helps, Please mark it as best answer.

Thanks,