Technology has always been a bridge, but today, it feels more like a mirror. With the rapid rise of AI , we are seeing things enter our lives and leave them at a pace we can barely track. To understand where this is going, we first have to understand how technology actually impacts the core of who we are. The Survivalist vs. The Ego Our minds are biologically wired for one thing: survival . We are designed to handle the worst-case scenario, an ancient instinct gifted to us by nature. We consider ourselves conscious decision-makers, but a critical question remains: Who is really making the call?
Here is the Sample code to prevent update and insert records between from date and end date in salesforce. This trigger have two events:-
before insert and before update
trigger Duplicatecheck on <Obejct> (before insert,before update) {
set<object > ListOfrecords= new set<object >([SELECT id,Valid_Form__c,Valid_To__c FROM <object>]);
for(<object> obj1 : ListOfrecords) {
for(<object> obj2: Trigger.new) {
if(obj2.VS_State__c== obj1.VS_State__c && obj2.vs_Tax_Type__c == obj1 .vs_Tax_Type__c){
if((obj2.Valid_To__c >= obj1.Valid_Form__c&& obj2.Valid_To__c <= obj1 .Valid_To__c ) ||
(obj2.Valid_Form__c>= obj1.Valid_Form__c&& obj2.Valid_To__c <= obj1 .Valid_To__c ) ||
(obj2.Valid_Form__c>= obj1.Valid_Form__c&& obj2.Valid_Form__c<= obj1 .Valid_To__c ) ||
(obj2.Valid_Form__c< obj1.Valid_To__c && obj2.Valid_To__c > obj1 .Valid_To__c )){
obj2.addError('record already exist between these dates.');
}
}
}
}
}Output:-
| Trigger to prevent insert or update duplicate records. |