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
SamwisematrixSamwisematrix 

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;

}

}

cmoylecmoyle

This part of your code doesn't make sense and I think you could delete it and fix your issue:

 

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);
}

 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: 

 

if (OptyMap.size() > 0 && OptyMap.containsKey(t.WhatId))

 

digamber.prasaddigamber.prasad

Hi,

 

I have modified your code. Please try this:-

 

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')) ) && OptyMap.containsKey(t.WhatId)){
				Optyrec.Last_Activity__c = t.ActivityDate;
			}

			if(!Ready4Update.contains(OptyRec.id)){

				OppList.add(OptyRec);   
				Ready4Update.add(OptyRec.id);

			}
		}
	}

	if(OppList.size() > 0){

		update oppList;

	}

}

 

Let me know if you still have any problem.

cmoylecmoyle

f(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 (((!t.subject.contains('Act-On Email')) ) && OptyMap.containsKey(t.WhatId)){
				Optyrec.Last_Activity__c = t.ActivityDate;
			}

 

if(!Ready4Update.contains(OptyRec.id)){

				OppList.add(OptyRec);   
				Ready4Update.add(OptyRec.id);

			}

 meaning your update will still try to update a variable with a null id.