• Shaowy-wowy
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I have setup a trigger to prevent users with a certain profile from deleting tasks. My trigger won't save to the server due to 0% test coverage, but I based on my understanding, my tyest code is testing the trigger just fine.

Here's my code:

trigger TaskNoDelete on Task (before delete) {

for (Task t : Trigger.old)
{
  if (UserInfo.getProfileId() == '00e600000015vZp')
  {
   t.addError('You are not authorized to delete tasks.');
  }
}
}



@isTest(SeeAllData=true)
public with sharing class TestTaskTriggers {

static testmethod void updatecharge() {

  User u = new User(alias = 'standt', email='standarduser@testorg.com',
  emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
  localesidkey='en_US', profileid = '00e600000015vZp', Center__c = 'Las Vegas, NV',
  timezonesidkey='America/Los_Angeles', username='shalstesteruser@testorg.com');
  insert u;

  Lead l = new Lead(Web_Salutation__c = 'Mrs.', LastName = 'Test',
  Gender__c = 'Female', LeadSource = 'Web Registrant',
  Referral_Source__c = 'Test Referral');

  Task task = new Task();
  task.Subject = 'Test Subject';
  task.ActivityDate = date.newInstance(2100, 4, 22);
  task.OwnerId = u.id;
  task.whatId = l.id;
  insert task;

  System.runAs(u)
  {
   try
   {
    delete task;
   }
   catch (DMLException e)
   {
    task.addError(e);
   }
  }
}


}




Any help is appreciated.