You need to sign in to do that
Don't have an account?

Help with error First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []:
Hi All,
I am getting below error :
public with sharing class TaskTriggerHandler {
private boolean trigger_isExecuting = false;
public TaskTriggerHandler(){
}
public void OnAfterInsert(Task[] newObjects){
// EXECUTE AFTER INSERT LOGIC
updateAccountActivityFields(newObjects);
}
public void OnAfterUpdate(Task[] oldObjects, Task[] updatedObjects, Map<ID, Task> ObjectMap){
//EXECUTE AFTER UPDATE LOGIC
updateAccountActivityFields(updatedObjects);
}
public void updateAccountActivityFields(Task[] taskRecords){
/* when a task of RecordType(Safelite_Task_Record_Type) is created/updated either from Account or Contact then
update Account fields : Last_Face_to_Face_Activity__c, Last_Visited_By__c & Last_Call_Activity__c based on task type
*/
// find task record type
RecordType taskRec = [SELECT Id FROM RecordType WHERE SobjectType ='Task' AND DeveloperName ='Safelite_Task_Record_Type'];
//Set of Account IDs getting updated
Set<ID> aid = new Set<ID>();
List<Account> accountsToUpdate = new List<Account>();
Account a;
//Map of Account IDs and Accounts
Map<id,account> accMap = new Map<id,account>();
//Get all the contactIds and accountIds of the task being inserted/updated
for(Task tk : [SELECT Id, LastModifiedBy.name, type, LastModifiedDate, CreatedDate, RecordTypeId, whoid, whatid FROM task WHERE id in :taskRecords]){
if(tk.RecordTypeId == taskRec.Id && tk.Whoid!=null){
aid.add(tk.whatid);
a = new Account(id = tk.WhatId);
//convert task's CreatedDate, datetime to date
Date createdDateJustDate = date.newinstance(tk.CreatedDate.year(), tk.CreatedDate.month(), tk.CreatedDate.day());
//update the activity fields on account with Task's lastModifiedDate and LastModifiedBy based on Task Type
if(tk.type=='Face 2 Face Meeting' || tk.type=='Lunch'){
a.Last_Face_to_Face_Activity__c = createdDateJustDate;
a.Last_Visited_By__c = tk.LastModifiedBy.name;
}
else{
a.Last_Call_Activity__c = createdDateJustDate;
}
//Populate accMap with the Account IDs and Account record
accountsToUpdate.add(a);
accMap.put(a.id,a);
}
}
if(!accMap.isEmpty()){
Update accMap.values();
}
}
}
I am getting below error :
public with sharing class TaskTriggerHandler {
private boolean trigger_isExecuting = false;
public TaskTriggerHandler(){
}
public void OnAfterInsert(Task[] newObjects){
// EXECUTE AFTER INSERT LOGIC
updateAccountActivityFields(newObjects);
}
public void OnAfterUpdate(Task[] oldObjects, Task[] updatedObjects, Map<ID, Task> ObjectMap){
//EXECUTE AFTER UPDATE LOGIC
updateAccountActivityFields(updatedObjects);
}
public void updateAccountActivityFields(Task[] taskRecords){
/* when a task of RecordType(Safelite_Task_Record_Type) is created/updated either from Account or Contact then
update Account fields : Last_Face_to_Face_Activity__c, Last_Visited_By__c & Last_Call_Activity__c based on task type
*/
// find task record type
RecordType taskRec = [SELECT Id FROM RecordType WHERE SobjectType ='Task' AND DeveloperName ='Safelite_Task_Record_Type'];
//Set of Account IDs getting updated
Set<ID> aid = new Set<ID>();
List<Account> accountsToUpdate = new List<Account>();
Account a;
//Map of Account IDs and Accounts
Map<id,account> accMap = new Map<id,account>();
//Get all the contactIds and accountIds of the task being inserted/updated
for(Task tk : [SELECT Id, LastModifiedBy.name, type, LastModifiedDate, CreatedDate, RecordTypeId, whoid, whatid FROM task WHERE id in :taskRecords]){
if(tk.RecordTypeId == taskRec.Id && tk.Whoid!=null){
aid.add(tk.whatid);
a = new Account(id = tk.WhatId);
//convert task's CreatedDate, datetime to date
Date createdDateJustDate = date.newinstance(tk.CreatedDate.year(), tk.CreatedDate.month(), tk.CreatedDate.day());
//update the activity fields on account with Task's lastModifiedDate and LastModifiedBy based on Task Type
if(tk.type=='Face 2 Face Meeting' || tk.type=='Lunch'){
a.Last_Face_to_Face_Activity__c = createdDateJustDate;
a.Last_Visited_By__c = tk.LastModifiedBy.name;
}
else{
a.Last_Call_Activity__c = createdDateJustDate;
}
//Populate accMap with the Account IDs and Account record
accountsToUpdate.add(a);
accMap.put(a.id,a);
}
}
if(!accMap.isEmpty()){
Update accMap.values();
}
}
}
On which line you are getting this error ??
Use this code .. you need to check the what id not who id