问题描述
即使我分配了一个系统管理员配置文件,并且对订单行项目对象拥有 CRUD 权限,当我尝试通过我的顶点类中的 DML 操作删除订单项目记录时,我收到以下错误。
System.DmlException: Delete Failed. First exception on row 0 with id 8022M00000ANsKKQA1; first error: INSUFFICIENT_ACCESS_OR_READONLY,insufficient access rights on object id: []
我已将 Apex 类编写为“不共享”,以避免与共享规则相关的任何冲突。但是,我仍然收到此错误。任何人都可以让我知道为什么会发生这种情况。我从 after update 触发器 调用这个类此外,我也使用相同的类插入客户历史记录。顶点类如下。
public without sharing class LineItemHistoryRecordCreation {
public LineItemHistoryRecordCreation() {}
public void createLineItemHistoryRecord(List<OrderItem> ordItemList) {
List<Id> oliIdList = new List<Id>();
List<History__c> historyList = new List<History__c>();
for(OrderItem oli : ordItemList) {
oliIdList.add(oli.Id);
History__c his = new History__c();
his.Change_Log__c = 'Order Product record deleted-OrderNumber ' + oli.OrderId + '-' + oli.Id + '-' + oli.OB_Order_ID__c;
his.History_Type__c = 'Order Product-Deleted';
his.History_DateTime__c = DateTime.Now();
his.Record_Name__c = oli.Id;
his.Prior_Value__c = 'Active';
his.New_Value__c = 'Deleted';
historyList.add(his);
}
insert historyList;
List<OrderItem> oliList = [SELECT Id FROM OrderItem WHERE Id IN :oliIdList];
System.debug('order List akki' + oliList);
if(!oliList.isEmpty()) {
delete oliList;
}
}
}
有人可以帮助我理解和解决这个问题吗?提前致谢。