• Colby Bridges
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Ask: As a Sales Manager I would like to limit users ability to create tasks if an Opportunity has been closed for more than 4 days. 
As an Admin a Validation Rule doesn't seem like a viable solution. Trying to create a Trigger but running into some issues.

Problem - Line 5 - Inequality Operator not allowed for this type: Object
IF (a.WhatId!=null && String.valueOf(a.WhatId).startsWith('006')&& a.What.get('CloseDate') < (System.today()- 4) &&(RoleId =='00E800000029UCT'))
Trying to look at opp close date and evaluate if 4 days has past. If so, want to restrict ability to create tasks for certain role. 
Could someone help? Of if there is a better solution?


Trigger:
trigger NoTaskCreationForSE on Task (before insert) {
    String RoleId = UserInfo.getUserRoleId();
    for (Task a : Trigger.new)    
        
    IF (a.WhatId!=null && String.valueOf(a.WhatId).startsWith('006')&& a.What.get('CloseDate') < (System.today()- 4) &&(RoleId =='00E800000029UCT'))
        
    {
        a.addError('You Cannot Add Tasks Once An Opp Has Been Closed For More Than 4 Days');
    }
        
}