• calmark
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies

I am really knew to all this and having trouble deploying a trigger that will udpate a field in a contact when the status of an activity changes.  At this point I have the trigger working just find but the class I created for testing fails and I have no idea why.  Thank you for taking the time to thelp!  

 

The message I get when I run the class is: 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Update_Last_VM_Left: 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.Update_Last_VM_Left: line 7, column 1: []

 

Stack Trace:

Class.TaskTestMethod.TestTasktrigger: line 12, column 1

 

 

And here's my code:

 

Trigger:

1
2
3
4
5
6
7
8
9
trigger Update_Last_VM_Left on Task (after insert, after update)
{
  Task ts= Trigger.new[0];
  if(ts.Status == 'VM Left'){
      Contact contactToUpdate = new Contact(id=ts.WhoID);
      contactToUpdate.Last_VM_Left__c = date.today();
      update contactToUpdate;
  } 
}

 

Class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@isTest
private class TaskTestMethod{
static testMethod void TestTasktrigger()
    {
            Task[] CreateTask = new Task[]{};
            Contact[] CreateContact = new Contact[]{};
            for(Integer x=0; x<100;x++){
            Task ts = new Task(Subject='Apex Test',Status='VM Left');
            CreateTask.add(ts);    
            }  
        Test.startTest();
        insert CreateTask;
        Test.stopTest(); 
    }
}

 

  • September 29, 2012
  • Like
  • 0

oh my...you stop programming for 10 years, the world changes, and you have to start from step 1.  I need help :)

 

I created in my sandbox the following trigger:

 

trigger Update_Last_VM_Left on Task (after insert, after update)
{
Task ts= Trigger.new[0];
if(ts.Status =='VM Left'){
Contact contactToUpdate = new Contact(id=ts.WhoID);
contactToUpdate.Last_VM_Left__c = ts.activitydate;
}
}

 

I am not trying to deploy it to production and it fails because:

 

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required

 

I am clueless as to what I need to do next, any help would be greatly appreicated!

  • September 27, 2012
  • Like
  • 0

I am really knew to all this and having trouble deploying a trigger that will udpate a field in a contact when the status of an activity changes.  At this point I have the trigger working just find but the class I created for testing fails and I have no idea why.  Thank you for taking the time to thelp!  

 

The message I get when I run the class is: 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Update_Last_VM_Left: 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.Update_Last_VM_Left: line 7, column 1: []

 

Stack Trace:

Class.TaskTestMethod.TestTasktrigger: line 12, column 1

 

 

And here's my code:

 

Trigger:

1
2
3
4
5
6
7
8
9
trigger Update_Last_VM_Left on Task (after insert, after update)
{
  Task ts= Trigger.new[0];
  if(ts.Status == 'VM Left'){
      Contact contactToUpdate = new Contact(id=ts.WhoID);
      contactToUpdate.Last_VM_Left__c = date.today();
      update contactToUpdate;
  } 
}

 

Class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@isTest
private class TaskTestMethod{
static testMethod void TestTasktrigger()
    {
            Task[] CreateTask = new Task[]{};
            Contact[] CreateContact = new Contact[]{};
            for(Integer x=0; x<100;x++){
            Task ts = new Task(Subject='Apex Test',Status='VM Left');
            CreateTask.add(ts);    
            }  
        Test.startTest();
        insert CreateTask;
        Test.stopTest(); 
    }
}

 

  • September 29, 2012
  • Like
  • 0

oh my...you stop programming for 10 years, the world changes, and you have to start from step 1.  I need help :)

 

I created in my sandbox the following trigger:

 

trigger Update_Last_VM_Left on Task (after insert, after update)
{
Task ts= Trigger.new[0];
if(ts.Status =='VM Left'){
Contact contactToUpdate = new Contact(id=ts.WhoID);
contactToUpdate.Last_VM_Left__c = ts.activitydate;
}
}

 

I am not trying to deploy it to production and it fails because:

 

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required

 

I am clueless as to what I need to do next, any help would be greatly appreicated!

  • September 27, 2012
  • Like
  • 0