Skip to main content
I need to create a trigger where (tot.Date_vod__c < (THIS_YEAR(system.today())-1-11))

I want to avoid users from deleting TOT with Date_vod__c that is less than Jan 11 of this year

I am not sure if I am doing it correctly.
2 answers
  1. Sep 7, 2016, 11:21 PM
    Hi Carmilyn,

    Try using a simple trigger like this.

     

    trigger TOTTrigger on TOT (before delete) {

    for (TOT deleteMe : trigger.Old) {

    if (deleteMe.Date_Vod__c < Date.NewInstance(Date.today().year(), 1, 11)) {

    deleteMe.addError('Meaningful Error Message.');

    }

    }

    }

    The above code basically checks compares the date on the record to Jan 1 of this year. If the record has a date thatless than that then it will result in error.

    Hope this helps!

    AM
0/9000