对于循环:“休息”后的奇怪行为发生的历史

时间:2013-07-24 12:14:31

标签: salesforce apex-code xmlnode force.com

我遇到了一些我所拥有的功能的奇怪行为,我无法解释发生了什么。我已将它展示给一位同样感到困惑的同事。

在我的问题中包含的代码中。

  • 在调试行“Value =”之后,我的for循环正在被正确地破坏并且调试行 执行“Completed Value =”,然后执行我的函数“updateBookingRecordWithConfirmationResponse”,然后是调试行“After updatefunctionCalled”。到目前为止这一切都是正确的。接下来发生的事情是奇怪的。
  • 调试语句“Completed Value =”再次执行,函数“updateBookingRecordWithConfirmationResponse”再次执行调试行“after updatefunctionCalled”。这不应该是第二次发生。我的函数“walkThroughReservationNode”没有被再次调用,而是调试日志并调用updateBookingRecordWithConfirmationResponse。

从这里详细说明的代码中,如果有人能够看到我的代码中的错误在哪里,或者在for循环再次执行之后可能导致进程的原因,那么对此有任何帮助将不胜感激。

提前致谢。

 private void walkThroughReservationNode(DOM.XmlNode envelope) {
     System.debug('in walkThroughReservationNode');
     ReservationConfirmationWrapper reservationConfirmationWrapper =
                                        new reservationConfirmationWrapper();
     for (DOM.XMLNode childNode : envelope.getChildElements()) {
         system.debug('in for loop');
         if (childNode.getName() == 'UniqueID') {
             System.debug('uniqueIDNodeVal=' + childNode.getAttribute('ID', ''));
             reservationConfirmationWrapper.bookingId = childNode.getAttribute('ID', '');
         } else if (childNode.getName() == 'ReservationID') {
             System.debug('Value=' + childNode.getAttribute('ID_Value', ''));
             reservationConfirmationWrapper.confirmationNumber = childNode.getAttribute('ID_Value', '');
             break;
         } else if (childNode.getName() == 'Warning') {
             System.debug('Warning Exists ' + childNode.getText());
             reservationConfirmationWrapper.warningMessage = childNode.getText();
             break;
         } else {
             system.debug('before new walkthrough');
             walkThroughReservationNode(childNode);
         }
     }
     System.debug('Completed Value=' + reservationConfirmationWrapper.confirmationNumber);
     updateBookingRecordWithConfirmationResponse(reservationConfirmationWrapper);
     System.debug('After updatefunctionCalled');
 }

2 个答案:

答案 0 :(得分:0)

请您发布一堆调试日志消息吗?

我的意思是这样的:

dbgMsg1
dbgMsg2
dbgMsg3
....
dbgMsgN

按顺序执行,因为根据您的描述,它不是完全可以理解的(使用System.debug(LoggingLevel.INFO, 'dbgMsg')来过滤所需的dbg消息)

从我的旁边代码似乎是正确的,但是:

  • 什么是调用walkThroughReservationNode的上下文?是VF /触发/网络服务/等等吗?
  • updateBookingRecordWithConfirmationResponse做了什么?任何可能再次调用walkThroughReservationNode的DML?
  • System.debug('in walkThroughReservationNode');出现了多少次?

答案 1 :(得分:0)

嗨Pavel感谢您的帮助。我发现我的错误是由于行

} else {system.debug('在新的演练之前'); walkThroughReservationNode(childNode); }

这会导致完整的演练再次发生,从而导致updateBookingRecordWithConfirmationResponse(reservationConfirmationWrapper);每次调用的行都不是我应该做的。

感谢您的帮助。

相关问题