You need to sign in to do that
Don't have an account?
tantonio
Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call
I am trying to figure out how to pass the ID of an existing record I am trying to update. I get the above error in the debug logs after running this method.
As a background, I have a trigger after update running the passes trigger.new into a method called MarqueeUpdate. From there, I query to find the existing ChangeRecord__c. I need the ID of that ChangeRecord__c to update.
I cannot figure out how to pass the id of that record to my update statement.
As a background, I have a trigger after update running the passes trigger.new into a method called MarqueeUpdate. From there, I query to find the existing ChangeRecord__c. I need the ID of that ChangeRecord__c to update.
I cannot figure out how to pass the id of that record to my update statement.
//Updating existing records public static void MarqueeUpdate(List<NI_MarqueeFeature__c> marqueeUpdate){ //marqueeUpdate contains trigger.new for (NI_MarqueeFeature__c mi : marqueeUpdate){ String Id = mi.Id; List <ChangeRecord__c> upMarquee = [SELECT ID FROM ChangeRecord__c WHERE ChangeRecord__c.ID__c = :Id]; if (marqueeUpdate.size()>0) { ChangeRecord__c um = new ChangeRecord__c (); um.ID__c = mi.id; um.LastMod__c = mi.LastModifiedDate; upMarquee.add(um); try { update um; } catch (system.DmlException e) { system.debug (e);} } } }
List <ChangeRecord__c> updatedChangeRecords = new List <ChangeRecord__c>(); // Needed to bulkify the Code
for (NI_MarqueeFeature__c mi : marqueeUpdate){
//String Id = mi.Id; // Removing as established in query
ChangeRecord__c updateChangeRecord = [SELECT ID, LastMod__c
FROM ChangeRecord__c
WHERE ChangeRecord__c.ID__c = :mi.Id LIMIT 1];
//if (marqueeUpdate.size()>0) { // This line shouldn't be needed. Can't iterate over an empty list
//ChangeRecord__c um = new ChangeRecord__c (); Don't need a new record, updating existing
//um.ID__c = mi.id; // Removing as established in query
updateChangeRecord.LastMod__c = mi.LastModifiedDate; // Changed Variable Name
updatedChangeRecords.add(updateChangeRecord); // Changed Variable Name
/*
try {
update um;
}
catch (system.DmlException e) {
system.debug (e);
}*/
//}
}
// See https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database.htm#apex_System_Database_update
Database.SaveResult[] srList = Database.update(updatedChangeRecords, false);
// See https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database_saveresult.htm#apex_methods_system_database_saveresult
for (Database.SaveResult sr : srList) {
if (sr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully updated ChangeRecord Id: ' + sr.getId());
}
else {
// Operation failed, so get all errors
for(Database.Error err : sr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Fields that affected this error: ' + err.getFields());
}
}
}
All Answers
Change line # 14 to um.ID=mi.id which will fix the issue
Please mark this as the best answer if it resolved your issue.
Thanks for the response.
The problem is there are two objects at play. When NI_MarqueeFeature__c object records are updated I need to modify a cooresponding record in ChangeRecord__c object.
So um.id is actually not mi.id because they are records from different objects. um.ID__c is a custom fieild on ChangeRecord__c object that is used to create the relationship.
Please let me know your thoughts.
Can you describe more about what you are trying to do with the code?
Its the second option. I need to retrieve the record. That is what this query is doing:
The :Id variable in the where clause contains the id I need to see if there is an existing record in ChangeRecord__c.
If there is, then I need to update that record with some new values. That query does return 1 record, just like it should. I need to then get the ID of that returned record to do the DML further down in the method.
Hope that helps!
List <ChangeRecord__c> updatedChangeRecords = new List <ChangeRecord__c>(); // Needed to bulkify the Code
for (NI_MarqueeFeature__c mi : marqueeUpdate){
//String Id = mi.Id; // Removing as established in query
ChangeRecord__c updateChangeRecord = [SELECT ID, LastMod__c
FROM ChangeRecord__c
WHERE ChangeRecord__c.ID__c = :mi.Id LIMIT 1];
//if (marqueeUpdate.size()>0) { // This line shouldn't be needed. Can't iterate over an empty list
//ChangeRecord__c um = new ChangeRecord__c (); Don't need a new record, updating existing
//um.ID__c = mi.id; // Removing as established in query
updateChangeRecord.LastMod__c = mi.LastModifiedDate; // Changed Variable Name
updatedChangeRecords.add(updateChangeRecord); // Changed Variable Name
/*
try {
update um;
}
catch (system.DmlException e) {
system.debug (e);
}*/
//}
}
// See https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database.htm#apex_System_Database_update
Database.SaveResult[] srList = Database.update(updatedChangeRecords, false);
// See https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database_saveresult.htm#apex_methods_system_database_saveresult
for (Database.SaveResult sr : srList) {
if (sr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully updated ChangeRecord Id: ' + sr.getId());
}
else {
// Operation failed, so get all errors
for(Database.Error err : sr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Fields that affected this error: ' + err.getFields());
}
}
}
I only had to make a small change to get it to work:
Thanks again. This is working now :-)