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
JonSimmonsJonSimmons 

Problem saving Trigger to Server

I have developed a simple trigger that works fine on my dev org and a clients Enterprise org.  I'm attempting to create this same Trigger on another client's org but Eclipse wont save it for me.
 
I have created the project so I have a stub trigger without issue but when I copy in my trigger code and try to save I just get a warning that says "File only saved locally, not on server", but no reason why and no actual error.
 
I found that if I set the Trigger to Inactive then Eclipse will upload the code but I cannot Activate the trigger.
 
Is there a permission that I dont know about that will allow me to create a trigger but not actvate it?  Is there some trick to activating this trigger that I didnt need on the other orgs?
 
Thanks
Jon
 
 
JonPJonP
Make sure you're using the latest version of the Force.com IDE (Summer '08 / v13.0.0).

From the Force.com Project you've created against your developer org, containing the trigger you want to deploy, right-click the "src" folder and in the context menu select Force.com > Deploy to Server...

This wizard will walk you through the process of deploying your code to another Salesforce organization, and should provide better feedback as to why the deployment is failing.

Since you did not mention deploying an Apex Class at the same time as your trigger, my guess is that your code does not meet the code coverage minimums to deploy to a production organization.  You will need to create an Apex Class and declare one or more TestMethods which exercise your trigger, and then deploy the trigger and the test class(es) at the same time through the Deploy to Server wizard.
JonSimmonsJonSimmons
Thanks, it looks like you are right about the test coverage.
I will have to add a few more lines to test and try again.
 
Thanks
Jon
 
JonSimmonsJonSimmons

 

I understand that I have to create some Unit Tests that can be used to test this trigger, but I'm not sure that's even possible.

This trigger doesn't result in any changes that I can test for.

 

My code is below, the Trigger fires After Update of a Task.  If the Creator is different then the Owner (meaning someone created a task and assigned it to another user) AND the Task has just been Completed, then an eMail will be generated to inform the creator that the task is complete.

I can create a task, then update it as Completed but I'm not sure how to test to verify that an eMail has been generated and sent.

I suppose I could write back to the task with the results of the eMail send, but testing one value probably isn't going to cover the 75% coverage requirement.

 

Can you provide any guidance?

Thanks

Jon

Code:
trigger TaskTestTrigger on Task (after update) 
{

//if the Task has just been marked as completed AND the OwnerId is different then the CreatorId
//generate an eMail to the Creator to inform them of the Task's Completion

 id theOwnerId = Trigger.new[0].OwnerId;
 id theCreatedById = Trigger.new[0].CreatedById;
 string theCreatedByeMail;
 string theOwnerName;
 
 if((Trigger.old[0].IsClosed == false) && (Trigger.new[0].IsClosed == true))
 {
  //it looks like this task has just been closed
  //let's verify that the creator is not the owner
  if(theCreatedById <> theOwnerId)
  {
   //it looks like the creator is not the owner
   
   //lets get the creator's eMail address
   User[] theCreator;
   theCreator = [Select id,email FROM user WHERE id = :theCreatedById];
   theCreatedByeMail = theCreator[0].email;
   
   //lets get the owner's name
   User[] theOwner;
   theOwner = [Select id,name,email FROM user WHERE id = :theOwnerId];
   theOwnerName = theOwner[0].name;
   
   
   // let's create an eMail to inform the creator that the task has been completed
   Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

   email.setSubject('Assigned Task Completed');
   email.setReplyTo(theCreatedByeMail);
   email.setSaveAsActivity(false);
   
   email.setPlainTextBody('A task that you assigned to another person has completed. ' +
               '\nThe Task Details are Below;' +
               '\n\n Assigned To: ' + theOwnerName +
                     '\n Task Subject: ' + Trigger.new[0].Subject +
                     '\n Task Description: ' + Trigger.new[0].description +
                     '\n Task Status: ' + Trigger.new[0].status +
                     '\n Task URL: http://na1.salesforce.com/' + Trigger.new[0].id +
         '\n\n');

       String[] toAddresses = new String[] {theCreatedByeMail};  //the address to send to
       email.setToAddresses(toAddresses);
       
       Messaging.SendEmailResult[] sendResult;
       //send the eMail
       sendResult = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
       
   }
 
  
 }
 //Done
}//trigger