+ Start a Discussion
ckellieckellie 

Need to Write Test Class for Apex Trigger

I am tring to write my first test class for an apex trigger and am having a tough time understanding what needs to be tested. Below is my trigger:

 

trigger setTaskDueDate on Task (before insert, before update) {

   Task[] tasks = trigger.new;

   for (integer i = 0; i < tasks.size(); i++) {
      Task ntask = tasks[i];
      ntask.Due_Date__c = nTask.ActivityDate;
   }

 

 

May I have any direction?

Best Answer chosen by Admin (Salesforce Developers) 
AlsoDougAlsoDoug
You are trying to set the value of a variable ( Activity ) that you have never declared.

All Answers

jeffdonthemic2jeffdonthemic2

You can take a look at the following blog post. There are alot of links back to the appropriate Salesforce.com article links.

 

Writing Bulk Triggers For Salesforce.com

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com 

 

ckellieckellie

Thank you for the direction. Upon looking at the examples, I have been able to add the following to the trigger.

 

trigger setTaskDueDate on Task (before insert, before update) { list<Task> theTasks = new list<Task>(); list<String> cDue = new list<String>(); map<String, String> theMap = new map<String, String>(); Task[] tasks = trigger.new; for(Task t:trigger.new) { if(t.ActivityDate!= null) { Activity.ParentID = theTasks.WhatID; theTasks.ActivityDay = tasks.Date_Due__c; theTasks.put(t.ActivityDate); for (integer i = 0; i < tasks.size(); i++) { Task nt = tasks[i]; t = t.ActivityDate; }}}}

 

 

But now I am recieving the following error:

Error: Compile Error: Variable does not exist: Activity.ParentID at line 13 column 8

 

 

 

How do I solve this error.

AlsoDougAlsoDoug
You are trying to set the value of a variable ( Activity ) that you have never declared.
This was selected as the best answer
ckellieckellie
Thank you