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
Dagny FernandesDagny Fernandes 

Error in trigger: MISSING_ARGUMENT, Id not specified in an update call

Hi Frends,

Iam getting the below error in trigger after Update 
TicketStatus: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0AO000000Ak6Y6MAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TicketStatus: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Class.TicketStatusHandler.onAfterUpdate:

this error is in the line number 65 DML operation update. I added the System debug statement in line number 64 and iam getting the ID of the record. Am i missing anything in the below code. need help ASAP 

Thanks in advance.
 
//-- After Update
	 
	 public void onAfterUpdate(final List<Escalation__c> newObjects,final List<Escalation__c> oldObjects,final Map<Id, Escalation__c> newObjectsMap,final Map<Id, Escalation__c> oldObjectsMap){
	 List<Escalation__Share> EscalationShareList 			= new List<Escalation__Share>();
	 List<Escalation__Share> EscalationShareListToDelete 	= new List<Escalation__Share>();
	 List<Followers__c> FollowersList 						= new List<Followers__c>();
	 List<Escalation__c> ParentEscaUpdate 					= new List<Escalation__c>();
	 Map<Id,Id> toDeleteShareMap 							= new Map<Id,Id>();
	 map<Id, Escalation__c> parentEsca 						= new map<Id, Escalation__c>();
	 Escalation__c PrarentRec = new Escalation__c();
	 
		 for(Escalation__c escaParent: [SELECT Id,Name,Sys_Ticket_Count__c,RecordTypeId FROM Escalation__c WHERE RecordTypeId =: Constants_PicklistVariables.ESCALATION_RECORDTYPE_ID]){
		 		parentEsca.put(escaParent.Id, escaParent);
		 }
	 	
		 for(Escalation__c esca: newObjects){
		 	if(esca.RecordTypeId == Constants_PicklistVariables.TICKET_RECORDTYPE_ID && esca.Assigned_To__c != null && esca.Assigned_to__c != oldObjectsMap.get(esca.Id).Assigned_To__c){
	            Escalation__Share expShare = new Escalation__Share(
								              ParentId 		= esca.Id,
								              UserOrGroupId = esca.Assigned_To__c,
								              rowCause 		= Schema.Escalation__Share.rowCause.AssignedTo__c,
								              accessLevel 	= 'Edit'
								            );
	            
	            //Adding Followers
	            Followers__c follRec = new Followers__c();
	            follRec.Follower_Name__c = esca.Assigned_To__c;
	            follRec.Ticket__c 		 = esca.Id;
	            
	            FollowersList.add(follRec);
	            EscalationShareList.add(expShare);
	            toDeleteShareMap.put(esca.Id, oldObjectsMap.get(esca.Id).Assigned_To__c);
	            System.debug('toDeleteShareMap'+toDeleteShareMap);
		 	}
		 	if(esca.Escalation__c != null)
		 	PrarentRec = parentEsca.get(esca.Escalation__c);
		 	
		 }
		 
		 if(PrarentRec != null){
		 	List<Escalation__c> TicketRec = [SELECT Id,Name,RecordTypeId,Escalation__c,Category__c,Ticket_Status_Overall_Ops__c,Ticket_Status_Overall_Finance__c,Ticket_Status_Overall_Mar__c,Ticket_Status_Overall_Service__c,Ticket_Status_Overall_Tech__c FROM Escalation__c WHERE RecordTypeId =: Constants_PicklistVariables.TICKET_RECORDTYPE_ID AND Escalation__c =: PrarentRec.Id];
		 	Integer NonClosedTicketCounter = 0;
		 	System.debug('TicketRec'+TicketRec);
		 	for(Escalation__c tickRec: TicketRec){
		 		if(tickRec.Category__c == null)
		 			NonClosedTicketCounter = NonClosedTicketCounter + 1;
		 		if(tickRec.Category__c == 'Ops' && tickRec.Ticket_Status_Overall_Ops__c != 'Closed')
		 			NonClosedTicketCounter = NonClosedTicketCounter + 1;
		 		if(tickRec.Category__c == 'Finance' && tickRec.Ticket_Status_Overall_Finance__c != 'Closed')
		 			NonClosedTicketCounter = NonClosedTicketCounter + 1;
		 		if(tickRec.Category__c == 'Leads (Marketing)' && tickRec.Ticket_Status_Overall_Mar__c != 'Closed')
		 			NonClosedTicketCounter = NonClosedTicketCounter + 1;
		 		if(tickRec.Category__c == 'Service' && tickRec.Ticket_Status_Overall_Service__c != 'Closed')
		 			NonClosedTicketCounter = NonClosedTicketCounter + 1;
		 		if(tickRec.Category__c == 'Tech' && tickRec.Ticket_Status_Overall_Tech__c != 'Closed')
		 			NonClosedTicketCounter = NonClosedTicketCounter + 1;
		 	}
		 	System.Debug('NonClosedTicketCounter'+NonClosedTicketCounter);
		 	if(NonClosedTicketCounter == 0){
			 	/*Escalation__c parentRecord = parentEsca.get(PrarentRec.Id) ;
			 	parentRecord.Escalation_Status__c = 'Closed';
			 	update parentRecord;*/
			 	PrarentRec.Escalation_Status__c = 'Closed';
			 	System.debug('PrarentRec'+PrarentRec);
			 	update PrarentRec;
		 	}
		 }
		 
		 for(Escalation__Share expShare :[SELECT Id, ParentId, rowCause, UserOrGroupId FROM Escalation__Share WHERE ParentId in :toDeleteShareMap.keySet()]){
	        if(toDeleteShareMap.get(expShare.ParentId) != null && toDeleteShareMap.get(expShare.ParentId) == expShare.UserOrGroupId){
	            EscalationShareListToDelete.add(expShare);
	        }
	     }
	    
	     try{
		 	insert EscalationShareList;
		 	insert FollowersList;
		 	delete EscalationShareListToDelete;
		 }catch(Exception e){
		 	
		 }
		 
	 }

 
Best Answer chosen by Dagny Fernandes
bob_buzzardbob_buzzard
As you always instantiate an empty PrarentRec object (line 10) :
Escalation__c PrarentRec = new Escalation__c();
The null check on line 40 will always pass, and you will then attempt to update with a pretty much empty instance.

Looking at your code, I'd say that you should initialise this variable to null - that way you will only attempt escalation processing if the parent record exists.

All Answers

bob_buzzardbob_buzzard
As you always instantiate an empty PrarentRec object (line 10) :
Escalation__c PrarentRec = new Escalation__c();
The null check on line 40 will always pass, and you will then attempt to update with a pretty much empty instance.

Looking at your code, I'd say that you should initialise this variable to null - that way you will only attempt escalation processing if the parent record exists.
This was selected as the best answer
Dagny FernandesDagny Fernandes
Thanks a ton @bob you are the RockStar. 
tonantetonante
Sometimes the case is that you are trying to use Update on an object record that really needs to be upsert-ed or inserted first because you don't have the ID of the newly instantiated  object record  that you are trying to insert. The error message is a bit misleading because I had thought initially that it was saying that I had left out an Id paramter like Campaign.Id, or Account Id or even Contact Id when attempting to instantiate a campaign member record. first error: MISSING_ARGUMENT, Id not specified in an update call CampaignMember . I wish the message was more intuitive like "Cant update a campaign member without it being inserted first" or some such. Just my two cents.