You need to sign in to do that
Don't have an account?

trigger.oldmap returning same values as trigger.newmap
Here is the code snippit:
trigger WorkOrderJobRollUp on Work_Order__c (before update, after insert, after delete, after undelete) {
// Check to make sure work order is not being deleted
IF (trigger.isdelete == FALSE)
{
// Run trigger for all situations with the exception of the AFE Approval process
For(Work_Order__c wo : Trigger.New)
{
try
{
Work_Order__c beforeUpdate = Trigger.oldMap.get(wo.ID);
system.debug('Work Order ID New: ' + wo.ID);
system.debug('Work Order ID Old: ' + beforeUpdate.ID);
string oldstatus = beforeUpdate.Work_Order_Status__c;
system.debug('New WO Status: ' + wo.Work_Order_Status__c);
system.debug('Old WO Status: ' + beforeUpdate.Work_Order_Status__c);
system.debug('Old WO Status: ' + trigger.oldmap.get(wo.ID).Work_Order_Status__c);
system.debug('Old WO Status: ' + oldstatus);
IF (wo.Work_Order_Status__c == 'Approved' && beforeUpdate.Work_Order_Status__c == 'Pending Approval') return;
}
catch(exception e){}
}
}
Here is a snippit of the debug log:
14:09:14.853 (9285875790)|USER_DEBUG|[12]|DEBUG|Work Order ID New: a270j0000009ASKAA2 14:09:14.853 (9285880579)|STATEMENT_EXECUTE|[13] 14:09:14.853 (9285889523)|HEAP_ALLOCATE|[13]|Bytes:18 14:09:14.853 (9285894991)|HEAP_ALLOCATE|[13]|Bytes:37 14:09:14.853 (9285898897)|USER_DEBUG|[13]|DEBUG|Work Order ID Old: a270j0000009ASKAA2 14:09:14.853 (9285901596)|STATEMENT_EXECUTE|[15] 14:09:14.853 (9285907986)|VARIABLE_SCOPE_BEGIN|[15]|oldstatus|String|false|false 14:09:14.853 (9285914795)|VARIABLE_ASSIGNMENT|[15]|oldstatus|"Approved" 14:09:14.853 (9285916837)|STATEMENT_EXECUTE|[17] 14:09:14.853 (9285920997)|HEAP_ALLOCATE|[17]|Bytes:23 14:09:14.853 (9285925680)|USER_DEBUG|[17]|DEBUG|New WO Status: Approved 14:09:14.853 (9285928468)|STATEMENT_EXECUTE|[18] 14:09:14.853 (9285932040)|HEAP_ALLOCATE|[18]|Bytes:23 14:09:14.853 (9285935598)|USER_DEBUG|[18]|DEBUG|Old WO Status: Approved 14:09:14.853 (9285938221)|STATEMENT_EXECUTE|[19] 14:09:14.853 (9285964009)|HEAP_ALLOCATE|[19]|Bytes:23 14:09:14.853 (9285968749)|USER_DEBUG|[19]|DEBUG|Old WO Status: Approved 14:09:14.853 (9285971863)|STATEMENT_EXECUTE|[20] 14:09:14.853 (9285974149)|HEAP_ALLOCATE|[20]|Bytes:23 14:09:14.853 (9285978158)|USER_DEBUG|[20]|DEBUG|Old WO Status: Approved
The value of the Work Order Status field is changing from Pending Approval to Approved and I don't want the body of the trigger to fire off when this happens. How does the Trigger.newmap and trigger.oldmap values equal each other?
trigger WorkOrderJobRollUp on Work_Order__c (before update, after insert, after delete, after undelete) {
// Check to make sure work order is not being deleted
IF (trigger.isdelete == FALSE)
{
// Run trigger for all situations with the exception of the AFE Approval process
For(Work_Order__c wo : Trigger.New)
{
try
{
Work_Order__c beforeUpdate = Trigger.oldMap.get(wo.ID);
system.debug('Work Order ID New: ' + wo.ID);
system.debug('Work Order ID Old: ' + beforeUpdate.ID);
string oldstatus = beforeUpdate.Work_Order_Status__c;
system.debug('New WO Status: ' + wo.Work_Order_Status__c);
system.debug('Old WO Status: ' + beforeUpdate.Work_Order_Status__c);
system.debug('Old WO Status: ' + trigger.oldmap.get(wo.ID).Work_Order_Status__c);
system.debug('Old WO Status: ' + oldstatus);
IF (wo.Work_Order_Status__c == 'Approved' && beforeUpdate.Work_Order_Status__c == 'Pending Approval') return;
}
catch(exception e){}
}
}
Here is a snippit of the debug log:
14:09:14.853 (9285875790)|USER_DEBUG|[12]|DEBUG|Work Order ID New: a270j0000009ASKAA2 14:09:14.853 (9285880579)|STATEMENT_EXECUTE|[13] 14:09:14.853 (9285889523)|HEAP_ALLOCATE|[13]|Bytes:18 14:09:14.853 (9285894991)|HEAP_ALLOCATE|[13]|Bytes:37 14:09:14.853 (9285898897)|USER_DEBUG|[13]|DEBUG|Work Order ID Old: a270j0000009ASKAA2 14:09:14.853 (9285901596)|STATEMENT_EXECUTE|[15] 14:09:14.853 (9285907986)|VARIABLE_SCOPE_BEGIN|[15]|oldstatus|String|false|false 14:09:14.853 (9285914795)|VARIABLE_ASSIGNMENT|[15]|oldstatus|"Approved" 14:09:14.853 (9285916837)|STATEMENT_EXECUTE|[17] 14:09:14.853 (9285920997)|HEAP_ALLOCATE|[17]|Bytes:23 14:09:14.853 (9285925680)|USER_DEBUG|[17]|DEBUG|New WO Status: Approved 14:09:14.853 (9285928468)|STATEMENT_EXECUTE|[18] 14:09:14.853 (9285932040)|HEAP_ALLOCATE|[18]|Bytes:23 14:09:14.853 (9285935598)|USER_DEBUG|[18]|DEBUG|Old WO Status: Approved 14:09:14.853 (9285938221)|STATEMENT_EXECUTE|[19] 14:09:14.853 (9285964009)|HEAP_ALLOCATE|[19]|Bytes:23 14:09:14.853 (9285968749)|USER_DEBUG|[19]|DEBUG|Old WO Status: Approved 14:09:14.853 (9285971863)|STATEMENT_EXECUTE|[20] 14:09:14.853 (9285974149)|HEAP_ALLOCATE|[20]|Bytes:23 14:09:14.853 (9285978158)|USER_DEBUG|[20]|DEBUG|Old WO Status: Approved
The value of the Work Order Status field is changing from Pending Approval to Approved and I don't want the body of the trigger to fire off when this happens. How does the Trigger.newmap and trigger.oldmap values equal each other?
I apologize for my late response. !!
As per your requirement, I write a trigger in which you ll easily get the logic of the trigger i.e., how to match the value of old and new trigger.
for more information take a look on http://salesforce.stackexchange.com/questions/46790/how-to-avoid-recursive-trigger-other-than-the-classic-class-w-static-variable
Please let me know if this help. !
Thanks
Shivdeep
All Answers
Can you please explain the requirement for this trigger.
thanks
Shivdeep
I apologize for my late response. !!
As per your requirement, I write a trigger in which you ll easily get the logic of the trigger i.e., how to match the value of old and new trigger.
for more information take a look on http://salesforce.stackexchange.com/questions/46790/how-to-avoid-recursive-trigger-other-than-the-classic-class-w-static-variable
Please let me know if this help. !
Thanks
Shivdeep