• lawrep
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi,
i have created a trigger on task so that task records cannot be deleted for a particular profile/record type:

trigger taskDelete on Task (before delete)
{
      system.debug('inside taskdelete');
      Id taskId;
      ID shipperRecordType = [SELECT Id FROM RecordType WHERE Name = 'Interaction'].Id;
       for(task a:Trigger.old)
        {
          if(shipperRecordType == a.recordTypeId)
          {
            system.debug('a.recordTypeId' + a.recordTypeId);
            system.debug('shipperRecordType'+ shipperRecordType);
            a.addErro.('you cannot delete this task');
          }
         
       }

the trigger is working properly but the error message is coming like this on the next page:

Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "you cannot delete this task".
      
Is there any workaround for this???
Thanks

Hello.  i started a thread a few weeks ago regarding an issue where round robin assignment was failing when two nearly-simultaneous transactions would grab the same User for assignment (https://developer.salesforce.com/forums/ForumsMain?id=906F000000094RQIAY).  a solution that works for me (in theory at least) is to use the FOR UPDATE clause in my SOQL - along with a bit of error handling to confirm that no two threads will assign the same user.   so i've updated my code - but: is it possible to write test coverage for it?  

in my test coverage, i know ahead of time which user will be assigned via the round robin, so i do a FOR UPDATE query on that record - then i start the normal flow of the code.  however my test kept failing.  after much frustration, i believe i've found the issue explained in the documentation: "While the records are locked by a client, the locking client can modify their field values in the database in the same transaction."  My problem is (i think) that in my test coverage, i'm always the same "client."  

So my question is: is there a way to be a different client in a test coverage method?

thanks for your time.
chris