You need to sign in to do that
Don't have an account?
Todd B.
Error: Id not specified in an update call
I am trying to create a simple trigger that checks to see if a value is changed and if so, update a few fields and create a task. The update the few fields part works, but the create a task part does not. I receive the error message below.
Error Message: Error:Apex trigger Decide_Which_Address_to_Use caused an unexpected exception, contact your administrator: Decide_Which_Address_to_Use: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.Decide_Which_Address_to_Use: line 78, column 1
<pre>
trigger Decide_Which_Address_to_Use on SD_Member__c (before update) {
/*
Developer : Todd Barry
Created :
Last Modified : 03/19/2014
Test Class :
Objective :
*/
Task [] newTask = new Task[0];
// Variables
Date dtTaskDate = DateTime.now().addDays(+1).date();
For (SD_Member__c SD : Trigger.new){
SD_Member__c beforeUpdate = System.Trigger.oldMap.get(SD.Id);
if(beforeUpdate.Last_Address_Fail_Date__c != SD.Last_Address_Fail_Date__c){
If(sd.mailing_address__c == SD.NCOA_Address__c){
sd.Bad_NCOA_Address__c = SD.Mailing_Address__c;
sd.Bad_NCOA_City__c = sd.Mailing_city__c;
sd.Bad_NCOA_State__c = sd.mailing_state__c;
sd.Bad_NCOA_Zip__c = SD.Mailing_Zip__c;
SD.Send_Monthly_Letter__c = True;
newtask.add(new task(whatid=SD.Id,subject='Make 1st Follow Up Call',ActivityDate=dtTaskDate,Status='Not Started', ownerid=sd.OwnerId));
}
If (newtask.size()>0) update newtask;
}
}
}
</pre>
Any ideas?
Thanks,
Todd B.
Error Message: Error:Apex trigger Decide_Which_Address_to_Use caused an unexpected exception, contact your administrator: Decide_Which_Address_to_Use: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.Decide_Which_Address_to_Use: line 78, column 1
<pre>
trigger Decide_Which_Address_to_Use on SD_Member__c (before update) {
/*
Developer : Todd Barry
Created :
Last Modified : 03/19/2014
Test Class :
Objective :
*/
Task [] newTask = new Task[0];
// Variables
Date dtTaskDate = DateTime.now().addDays(+1).date();
For (SD_Member__c SD : Trigger.new){
SD_Member__c beforeUpdate = System.Trigger.oldMap.get(SD.Id);
if(beforeUpdate.Last_Address_Fail_Date__c != SD.Last_Address_Fail_Date__c){
If(sd.mailing_address__c == SD.NCOA_Address__c){
sd.Bad_NCOA_Address__c = SD.Mailing_Address__c;
sd.Bad_NCOA_City__c = sd.Mailing_city__c;
sd.Bad_NCOA_State__c = sd.mailing_state__c;
sd.Bad_NCOA_Zip__c = SD.Mailing_Zip__c;
SD.Send_Monthly_Letter__c = True;
newtask.add(new task(whatid=SD.Id,subject='Make 1st Follow Up Call',ActivityDate=dtTaskDate,Status='Not Started', ownerid=sd.OwnerId));
}
If (newtask.size()>0) update newtask;
}
}
}
</pre>
Any ideas?
Thanks,
Todd B.
From the above code it looks like you are trying to create new tasks so it should be an insert and not an update.Also you can do the insert operation after the for loop
When change if from Update to Insert, I get the following error:
Error:Apex trigger Decide_Which_Address_to_Use caused an unexpected exception, contact your administrator: Decide_Which_Address_to_Use: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Update_SD_Member_Enrollment_Progress_Status: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id a02R000000INf53IAD; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a02R000000INf53) is currently in trigger Decide_Which_Address_to_Use, therefore it cannot recursively update itself: [] Trigger.Update_SD_Member_Enrollment_Progress_Status: line 19, column 1: []: Trigger.Decide_Which_Address_to_Use: line 29, column 1
Regards,
Todd B.
http://kb.omni-ts.com/entry/68/
Could you please tell me what is being done in Update_SD_Member_Enrollment_Progress_Status trigger
<pre>
trigger Update_SD_Member_Enrollment_Progress_Status on Task (after insert, after update) {
/*
Automatically update the "Enrollment Progress Status" field, based upon the "Status" field
of the last Member Task
*/
// Tasks that meet criteria, and new tasks to create
Task[] qualifiedTasks = new Task[0], newTasks = new Task[0];
Date dt=DateTime.now().addDays(1).date();
Date rt=DateTime.now().addDays(1).date();
// Map of SD Members
Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>();
// Find qualifying tasks
for(Task record:Trigger.new)
if(Record.subject =='Make 1st Follow Up Call'||record.subject =='Make 2nd Follow Up Call'||record.subject =='Make 3rd Follow Up Call' &&
record.isclosed == True)
qualifiedtasks.add(record);
// Obtain member ID values
for(Task record:qualifiedtasks)
members.put(record.whatid,null);
// If there are any membes to query, do so.
if(!members.isempty())
members.putall([select id, Enrollment_Progress_Status__c from SD_Member__c where id in :members.keyset()]);
// For each qualifying task, check the current Enrollment_Progress_Status__c from SD_Member__c and assign
// to the strStatus variable. That way if the Task Status does not meet the critera below, the status
// will reamin it's current value
for(Task record:qualifiedtasks) {
String strStatus = members.get(record.whatid).Enrollment_Progress_Status__c;
// Set the strStatus based on the current Task Status value
If (record.Status == 'Not Started' ){
StrStatus = 'Attempting to Contact';}
If (record.Status == 'Left Message w/ Person' ){
StrStatus = 'Successful Contact';}
If (record.Status == 'Member Hung Up' ){
StrStatus = 'Successful Contact';}
If (record.Status == 'Phone # Invalid' ){
StrStatus = 'Phone # Invalid';}
If (record.Status == 'Reached Recording - No Msg Left' ){
StrStatus = 'Attempting to Contact';}
If (record.Status == 'Reached Target - Call Later' ){
StrStatus = 'Successful Contact';}
If (record.Status == 'Reached Recording - No Msg Left' ){
StrStatus = 'Attempting to Contact';}
If (record.Status == 'Reached Target - Call Later' ){
StrStatus = 'Successful Contact';}
If (record.Status == 'Reached Target - Declined - Copay' ){
StrStatus = 'Declined - Copay';}
If (record.Status == 'Reached Target - Declined - Other' ){
StrStatus = 'Declined - Other';}
If (record.Status == 'Reached Target - Declined - Transport' ){
StrStatus = 'Declined - Transportation';}
If (record.Status == 'Reached Target - Requested Info' ){
StrStatus = 'Decision Pending';}
If (record.Status == 'Reached Target - Sent to Care Coach' ){
StrStatus = 'Referred to Care Coach';}
If (record.Status == 'Reached Target - Thinking About It' ){
StrStatus = 'Decision Pending';}
SD_Member__C SD1 = new SD_Member__C(ID=record.WhatId,Enrollment_Progress_Status__c=strStatus);
update SD1;
} }
</pre>