2011-10-07 3 views
0

이 오류는 2 주 동안 나를 괴롭 히고 있습니다. 나는 Apex에 익숙하지 않으므로 쉽습니다.Salesforce.com - 기회 항목의 수량 변경이 잘못되었습니다.

나는 기회 갱신 후 방아쇠를 당겼다.

trigger triggerOpportunityCloseInstallDateChange on Opportunity (after update) 
{ 
    if(!Validator_cls.IsOpportunityScheduleUpdated()) 
    { 
     Validator_cls.SetOpportunityScheduleUpdatedDone(); 
     OpportunitySchedule.BuildScheduleAndUpdateDates(trigger.new, true); 
    } 
} 

업데이트 당 한 번만 호출되도록 래퍼가 있습니다.

해당 트리거가 실행되면 해당 광고 항목의 일정 날짜가 업데이트되고 해당 광고 항목 일정이 업데이트됩니다. 위에서 볼 수 있듯이

Error: Invalid Data. 
Review all error messages below to correct your data. 
Apex trigger triggerOpportunityCloseInstallDateChange caused an unexpected exception, contact your administrator: triggerOpportunityCloseInstallDateChange: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00kV0000002cHhTIAU; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (invalid quantity change on opportunity line item): [unknown]: Class.OpportunitySchedule.BuildScheduleAndUpdateDates: line 68, column 1 

그 오류가 난을 변경하지 않는거야,이 라인

update ItemsToUpdate; 

에 해당 : 나는 기회를 업데이트 할 때

public static void BuildScheduleAndUpdateDates(List<Opportunity> OpportunityList, Boolean DoUpdateItems) 
{ 
    system.debug('***********OpportunitySchedule    : BuildScheduleAndUpdateDates HIT'); 
    Map<String, Opportunity> OppMap = new Map<String, Opportunity>(); 
    List<OpportunityLineItem> ItemsToUpdate = new List<OpportunityLineItem>(); 
    List<String> IdList = new List<String>(); 

    for (Integer i = 0; i < OpportunityList.size(); i++) 
    { 
     IdList.add(OpportunityList[i].Id); 
     OppMap.put(OpportunityList[i].Id, OpportunityList[i]); 
    } 

    List<OpportunityLineItem> lineItems = [Select o.Id, (Select OpportunityLineItemId From OpportunityLineItemSchedules), o.Opportunity.Id, o.Systems_Add_On__c, o.ServiceDate, o.Product_Family__c, o.Schedule_Length__c , o.Monthly_Quantity__c, o.Monthly_Amount__c, o.Quantity 
              From OpportunityLineItem o 
              where o.Opportunity.Id in:IdList]; 

     for (OpportunityLineItem item : lineItems) 
     { 
      Opportunity opp_new = OppMap.get(item.Opportunity.Id); 

      Boolean hasSchedule = OpportunityProductLineItems.DoesLineItemHaveSchedule(item.Id); 

      if (opp_new.Term_Conversion__c != null) 
      { 
       item.ServiceDate = opp_new.CloseDate; 
      } 
      else 
      { 
       if(item.Product_Family__c == 'Systems') 
       { 
        if(item.Systems_Add_On__c == true) 
        { 
         item.ServiceDate = opp_new.Install_Date__c; 
         system.debug('***********BuildScheduleAndUpdateDates  : Systems With Systems Add On ' + item.ServiceDate); 
        } 
        else 
        { 
         item.ServiceDate = opp_new.Install_Date__c.addDays(30); 
         system.debug('***********BuildScheduleAndUpdateDates  : Systems With NO Systems Add On ' + item.ServiceDate); 
        } 
       } 
       else if(hasSchedule) 
       { 
        item.ServiceDate = opp_new.Install_Date__c.addDays(30); 
        system.debug('***********BuildScheduleAndUpdateDates  : Has Schedule ' + item.ServiceDate); 
       } 
       else 
       { 
        item.ServiceDate = opp_new.Install_Date__c; 
        system.debug('***********BuildScheduleAndUpdateDates  : No Schedule ' + item.ServiceDate); 
       } 
      } 

      //item.Quantity = 1; 
      ItemsToUpdate.add(item); 
      if(hasSchedule && !DoUpdateItems) 
      { 
       ProcessSchedule(item); 
      } 
     } 

    if(DoUpdateItems) 
    { 
     update ItemsToUpdate; 
    }  
    upsert schedulesToUpsert; 

} 

, 나는이 오류 수량을 계산합니다. 난 너무 혼란 스러워요. 그 행을 주석 처리하면 모든 것이 잘 작동합니다 (일정이 작성되고 업데이트 됨).

수량을 수동으로 설정할 수 있는지 확인하기 위해 item.Quantity = 1;을 입력했습니다.

이 오류는 무엇을 의미하며, 지나치게 빠져 나갈 수 있습니까?

답변

0

오류는 일반적으로 salesforce가 백엔드에서 동기화해야하는 특정 유형의 특수 필드로 인해 발생합니다. 예를 들어 기회에 대해 설정된 가격표와 다른 가격표가있는 품목을 추가하면 오류가 발생합니다.

이 경우 특정 양의 품목 금액에 의존하는 수량 또는 일정 레코드를 변경하는 일부 외부 요인이 원인 일 수 있습니다.

수량을 변경하는 외부의 힘에 대해서는 ProcessSchedule(item)을 호출하기 전후에 디버그 명령문을 넣으려고합니다. SObjects가 by reference 함수에 전달 되었기 때문에 실현하지 않고 함수가 item을 수정하고있을 가능성이 있습니다.

다른 코드를 모른 채 문제가 무엇인지 정확히 알기는 어렵지만, 이것이 올바른 방향으로 나아갈 수 있기를 바랍니다.

0

이 시도 :

OppMap.put(OpportunityList[i].Id, OpportunityList[i].clone(true, true)); 

복제 호출의 첫 번째 "사실은"당신의 sObjects의 ID를 유지하고 두 번째에 지시 참조 문제에 의해 파괴, 깊은 복사를 수행하기 위해 복제.

[편집]

다시 읽기 나는이 방법으로 문제가 해결되지 않을 수도 있음을 깨달았다 귀하의 게시물을 - 미안! 그러나 깊은 복제 트릭은 참조 문제에 도움이됩니다. 행운을 빕니다.

관련 문제