You need to sign in to do that
Don't have an account?
First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call
I have my code completed, but when I try to upload it to production I am getting an error: I am very new to code so any help would be greatly appriciated.
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LastActDate3: execution of AfterInsert
caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Trigger.LastActDate3: line 55, column 1: []
Here is my trigger code
trigger LastActDate3 on Task (after insert, after update) {
Set <ID> OptyIDs = new Set <ID> ();
Set<Id> Ready4Update = new Set<Id>();
List<Opportunity> OppList = new List<Opportunity>();
for (Task t: Trigger.new){
OptyIDs.add(t.WhatID);
}
Map<ID, Opportunity> OptyMap = new Map<ID, Opportunity> ([Select ID,Last_Activity__c from Opportunity where ID in :OptyIDs]);
for (Task t: Trigger.new){
if (t.WhatID != NULL){
Opportunity OptyRec = new Opportunity(); if(OptyMap.size()>0 && OptyMap.containsKey(t.WhatId)){ OptyRec = OptyMap.get(t.WhatID); If (t.subject <> null && t.subject.contains('Act-On Email') == false){ Optyrec.Last_Activity__c = t.ActivityDate; } if(!Ready4Update.contains(OptyRec.id)){ OppList.add(OptyRec); Ready4Update.add(OptyRec.id); } }
If (((!t.subject.contains('Act-On Email')) )){
Optyrec.Last_Activity__c = t.ActivityDate;
}
if(!Ready4Update.contains(OptyRec.id)){
OppList.add(OptyRec);
Ready4Update.add(OptyRec.id);
}
}
}
if(OppList.size() > 0){
update oppList;
}
}
This part of your code doesn't make sense and I think you could delete it and fix your issue:
Its happening outside the if statement that populates the OptyRec variable and so what you end up with is your 'update' dml statement is trying to do an update on blank objects (i.e. an object without an Id). Its also duplicating code that happens inside the if check:
Hi,
I have modified your code. Please try this:-
Let me know if you still have any problem.
digamberlucky's code does not fix the issue.
This block of code:
and this block of code:
are performing the same function except for the former, which is populating the OptyRec variable in the second line. The flaw in his code is when the OptyRec variable has a null Id. All your if checks will fail except this one :
meaning your update will still try to update a variable with a null id.