You need to sign in to do that
Don't have an account?
Antonino Cupi
Trigger oldMap return the New Value
Hi all,
I have a issue about the following trigger:
if( CPQ_StopRecursion_TriggerQuote.stopRecursiveTriggerQuote != true ) {
CPQ_StopRecursion_TriggerQuote.stopRecursiveTriggerQuote = true;
if(Trigger.isUpdate) {
try{
List<Apttus_Proposal__Proposal__c> quote = [select id, name, Apttus_Proposal__Approval_Stage__c, Apttus_QPApprov__Approval_Status__c, Delivery_Date__c, CPQ_Change_Delivery_Date__c from Apttus_Proposal__Proposal__c where id IN : quoteId ];
if ( quote != null){
for (Apttus_Proposal__Proposal__c proposal : quote){
Apttus_Proposal__Proposal__c oldQuote = new Apttus_Proposal__Proposal__c();
oldQuote = Trigger.oldMap.get(proposal.Id);
String oldStatus = oldQuote.Apttus_QPApprov__Approval_Status__c;
String oldStage = oldQuote.Apttus_Proposal__Approval_Stage__c;
String newStatus = proposal.Apttus_QPApprov__Approval_Status__c;
String newStage = proposal.Apttus_Proposal__Approval_Stage__c;
Date oldDeliveryDate = oldQuote.Delivery_Date__c;
Date newDeliveryDate = proposal.Delivery_Date__c;
if (oldStage == 'Approval Required' && newStage ==null){
proposal.Apttus_Proposal__Approval_Stage__c = 'Draft';
}
system.debug('*** '+ oldStage + ' ' + newStage);
system.debug('*** '+oldDeliveryDate+' '+proposal.Delivery_Date__c);
if ( (oldDeliveryDate != null) && ( (oldDeliveryDate > newDeliveryDate ) || ( oldDeliveryDate != newDeliveryDate && newStage == 'Denied') ) ){
proposal.Apttus_QPApprov__Approval_Status__c = 'Approval Required';
proposal.Apttus_Proposal__Approval_Stage__c = 'Approval Required';
proposal.CPQ_Change_Delivery_Date__c = TRUE;
}
quoteList.add(proposal);
}
}
}catch (Exception e) {
system.debug('*** error');
}
}
}
if (quoteList.size()>0){
update quoteList;
}
The problem is that when I change only the field "Delivery_Date__c" of my quote, the trigger.oldMap returns the new value of the field. In particular, only if I change also the field "Apttus_Proposal__Approval_Stage__c " (in the same time with the change of the field Delivery Date), the trigger.OldMap returns the correct old value of the field "Delivery_Date__c".
How can I fix my issue?
Thanks
I have a issue about the following trigger:
if( CPQ_StopRecursion_TriggerQuote.stopRecursiveTriggerQuote != true ) {
CPQ_StopRecursion_TriggerQuote.stopRecursiveTriggerQuote = true;
if(Trigger.isUpdate) {
try{
List<Apttus_Proposal__Proposal__c> quote = [select id, name, Apttus_Proposal__Approval_Stage__c, Apttus_QPApprov__Approval_Status__c, Delivery_Date__c, CPQ_Change_Delivery_Date__c from Apttus_Proposal__Proposal__c where id IN : quoteId ];
if ( quote != null){
for (Apttus_Proposal__Proposal__c proposal : quote){
Apttus_Proposal__Proposal__c oldQuote = new Apttus_Proposal__Proposal__c();
oldQuote = Trigger.oldMap.get(proposal.Id);
String oldStatus = oldQuote.Apttus_QPApprov__Approval_Status__c;
String oldStage = oldQuote.Apttus_Proposal__Approval_Stage__c;
String newStatus = proposal.Apttus_QPApprov__Approval_Status__c;
String newStage = proposal.Apttus_Proposal__Approval_Stage__c;
Date oldDeliveryDate = oldQuote.Delivery_Date__c;
Date newDeliveryDate = proposal.Delivery_Date__c;
if (oldStage == 'Approval Required' && newStage ==null){
proposal.Apttus_Proposal__Approval_Stage__c = 'Draft';
}
system.debug('*** '+ oldStage + ' ' + newStage);
system.debug('*** '+oldDeliveryDate+' '+proposal.Delivery_Date__c);
if ( (oldDeliveryDate != null) && ( (oldDeliveryDate > newDeliveryDate ) || ( oldDeliveryDate != newDeliveryDate && newStage == 'Denied') ) ){
proposal.Apttus_QPApprov__Approval_Status__c = 'Approval Required';
proposal.Apttus_Proposal__Approval_Stage__c = 'Approval Required';
proposal.CPQ_Change_Delivery_Date__c = TRUE;
}
quoteList.add(proposal);
}
}
}catch (Exception e) {
system.debug('*** error');
}
}
}
if (quoteList.size()>0){
update quoteList;
}
The problem is that when I change only the field "Delivery_Date__c" of my quote, the trigger.oldMap returns the new value of the field. In particular, only if I change also the field "Apttus_Proposal__Approval_Stage__c " (in the same time with the change of the field Delivery Date), the trigger.OldMap returns the correct old value of the field "Delivery_Date__c".
How can I fix my issue?
Thanks
thanks for the replying! In the system debug I want know the difference between the old values and new values. With my code I can see that the old value is equal to new value, in particular the trigger doesn't update my field because the if condition returns false.
Thanks,
Antonino