You need to sign in to do that
Don't have an account?
Smike25
Cannot_insert_update_activate_entity Help. Simple Trigger
Hello,
Our ORG was trying to fire workflow rules off formula values. After seeing that couldn't be done with a WFR, we decided to use a trigger. The trigger is on the Account and checks the field Activity_Test__c. If that date changes, we need that date value to change the value in the other field Activity_Status_Date__c.
The Trigger:
Our ORG was trying to fire workflow rules off formula values. After seeing that couldn't be done with a WFR, we decided to use a trigger. The trigger is on the Account and checks the field Activity_Test__c. If that date changes, we need that date value to change the value in the other field Activity_Status_Date__c.
The Trigger:
trigger CheckActivityDate on Account (before insert, before update) { for(Account a:Trigger.new) { if(system.trigger.OldMap.get(a.Id).Activity_Test__c != system.trigger.NewMap.get(a.Id).Activity_Test__c) { a.Activity_Status_Date__c = a.Activity_Test__c; } } }Upon running that it works correctly and is covered 75% through other test classes. The only line that wasn't covered is "a.Activity_Status_Date__c = a.Activity_Test__c;" which is what i'm assuming my problem lies. Do I need to build a standalone test class for this trigger or modify an existing one? It is causing the other triggers to error with "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CheckActivityDate: execution of BeforeInsert"
You can't use trigger.old or trigger.old map in the trigger insert operation.
Trigger.oldMap is only available in the update and delete trigger.
Add the condition to check only in the update operation
use Trigger.isupdate and trigger.isInsert to saperate the action .and write two action one for insert and other for update
And for test class write two different method for insert and update