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
Joe StolzJoe Stolz 

Workflow tasks due dates weekday trigger

Our Org has a number of workflow generated tasks to help our users know what to do for an opportunity depending on which stage the opportunity is in. This is working well, but we are running into the issue of tasks coming due on weekends. I know this has been asked a number of times and I have done some digging and found an answer here (https://developer.salesforce.com/forums/ForumsMain?id=906F00000008uTgIAI) that worked quite well for a specific subject.

I am very new to Apex triggers and could use some help customizing the code to only work for opportunities of certain record types. Here is the code I am using:
trigger WeekendTasks on Task (after insert)
{ for (Task tas : Trigger.new)
  {  if (Opp.RecordType == 'RPA NTE-Perm' , 'RPA NTE(No Bid)' , 'RPA RFQ' , 'RPA Capital')
   {   Date origin = Date.newInstance(1900,1,6);
      Date due = tas.ActivityDate;
        Integer x = origin.daysBetween(due);
     Integer day = Math.mod(x,7);
     if (day < 2 )
     {    Task tt = new Task (
          Id = tas.Id,
           ActivityDate = (tas.ActivityDate + 2),
        Description = String.valueOf(day)    );
           update tt;
     } 
   }
  }
}
This trigger does not work as you probably already knew. If I replace the bold underlined line with:
if (tas.Subject == 'Change Stage - Awarded')
Everything works perfectly, but I do not want the trigger to fire off the Subject.  Could someone help me out with how to fire this trigger only for tasks associated with opportunity record types RPA RFQ, RPA NTE-Perm, RPA Capital and RPA NTE(No Bid)?

Thank you
Best Answer chosen by Joe Stolz
Avidev9Avidev9
Ok to do so, you have to Query all the Opps and then Check the condtions.
Few steps
  • Check if a Opp is associated in WhatId
  • Query all the related opp in map
  • Use the map to check the recordType condition

All Answers

JuFeJuFe
Try this and see if it works:

if(Opp.RecordType.Name.equals('RPA NTE-Perm') || Opp.RecordType.Name.equals('RPA NTE(No Bid)') || Opp.RecordType.Name.equals('RPA RFQ') || Opp.RecordType.Name.equals('RPA Capital'))

Let me know how you get on! ;)
Joe StolzJoe Stolz
Hey JuFe,

Thank you for your help. Sadly, I am getting this error:

Compile Error: Variable does not exist: Opp.RecordType.Name at line 3 column 6

 
Avidev9Avidev9
Ok to do so, you have to Query all the Opps and then Check the condtions.
Few steps
  • Check if a Opp is associated in WhatId
  • Query all the related opp in map
  • Use the map to check the recordType condition
This was selected as the best answer
JuFeJuFe
Yes Joe, before checking for the RecordType condition, you need to retrieve the associated opps for the tasks in the trigger.
Joe StolzJoe Stolz

I'm very new to triggers and this is over my head right now. Could you give me a code sample of what you suggested?

Otherwise my solution right now is to create a new Task Record Type and use this record type as the default for all users who are being assigned workflow tasks and trigger off of this new record type.
 

Thank you again,