Эта ошибка мучает меня уже две недели. Я новичок в Apex, так что это может быть легко.
У меня есть триггер на Обновление после возможности.
trigger triggerOpportunityCloseInstallDateChange on Opportunity (after update)
{
if(!Validator_cls.IsOpportunityScheduleUpdated())
{
Validator_cls.SetOpportunityScheduleUpdatedDone();
OpportunitySchedule.BuildScheduleAndUpdateDates(trigger.new, true);
}
}
У меня есть обертка, чтобы он вызывался только один раз за обновление.
Когда этот триггер срабатывает, предполагается обновить дату графика для отдельных позиций, что, в свою очередь, обновит расписание позиций.
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;
}
Когда я обновляю возможность, я получаю эту ошибку:
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;
Как вы можете видеть выше, я не изменяю количество в этой позиции. Я весьма озадачен. Если я закомментирую эту строку, все будет нормально (расписание составлено и обновлено).
Я даже ввел item.Quantity = 1;
, чтобы посмотреть, смогу ли я установить количество вручную.
Что означает эта ошибка и как ее устранить?