You need to sign in to do that
Don't have an account?

error afterupdate
I got below error
"update failed Cannot_insert_update_activate_entity samplelotprocess: execution of afterupdate caused by ssytem dmlexception :update failed"
i noticed error shows in line no 82 at the time of update any idea why please advise me
trigger SampleLotProcess on Sample_Lot__c (after insert, after update) {
class SampleLotProcessHandler {
Sample_Lot__c[] oldRows;
Sample_Lot__c[] newRows;
Map<Id, Sample_Lot__c> oldMap;
Map<Id, Sample_Lot__c> newMap;
Map<String, RecordType> rtMap;
public void initialize(Sample_Lot__c[] oldRows, Sample_Lot__c[] newRows, Map<Id, Sample_Lot__c> oldMap, Map<Id, Sample_Lot__c> newMap) {
this.oldRows = oldRows;
this.newRows = newRows;
this.oldMap = oldMap;
this.newMap = newMap;
}
public void onAfterInsert() {
createReceipts();
}
public void onAfterUpdate() {
createReceipts();
}
public void createReceipts() {
Sample_Lot__c[] filteredRows = new Sample_Lot__c[0];
Set<Id> transferIds = new Set<Id>();
for (Sample_Lot__c item : newRows) {
if (item.Status__c != 'Confirmed') continue;
if (oldMap != null && item.Status__c == oldMap.get(item.Id).Status__c) continue;
filteredRows.add(item);
if (item.Original_Transfer_Transaction__c != null) {
transferIds.add(item.Original_Transfer_Transaction__c);
}
}
Sample_Transaction__c[] transfers = [select id, Status__c, Transferred_From__c from Sample_Transaction__c where id in :transferIds];
Map<Id, Sample_Transaction__c> transferMap;
if (transfers.isEmpty()) {
transferMap = new Map<Id, Sample_Transaction__c>();
} else {
transferMap = new Map<Id, Sample_Transaction__c>(transfers);
}
Sample_Transaction__c[] forIns = new Sample_Transaction__c[0];
for (Sample_Lot__c item : filteredRows) {
if (item.Status__c != 'Confirmed') continue;
if (oldMap != null && item.Status__c == oldMap.get(item.Id).Status__c) continue;
Sample_Transaction__c newReceipt = new Sample_Transaction__c();
newReceipt.Transfer_To__c = item.OwnerId;
newReceipt.Comments__c = item.Comments__c;
newReceipt.Quantity__c = item.Confirmed_Quantity__c;
newReceipt.OwnerId = item.OwnerId;
newReceipt.Transfer_To__c = item.OwnerId;
if (transferMap.containsKey(item.Original_Transfer_Transaction__c)) {
newReceipt.Transferred_From__c = transferMap.get(item.Original_Transfer_Transaction__c).Transferred_From__c;
transferMap.get(item.Original_Transfer_Transaction__c).Status__c = 'Confirmed';
}
if (getRtMap().containsKey('Reckitt_Receipt')) {
newReceipt.RecordTypeId = getRtMap().get('Reckitt_Receipt').Id;
}
newReceipt.Product__c = item.Product_ID__c;
newReceipt.Sample_Lot_ID__c = item.Id;
newReceipt.Transaction_Date__c = Date.today();
forIns.add(newReceipt);
}
if (!forIns.isEmpty()) {
insert forIns;
}
if (!transferMap.isEmpty()) {
update transferMap.values();
}
}
public Map<String, RecordType> getRtMap() {
if (rtMap == null) {
rtMap = new Map<String, RecordType>();
RecordType[] rtList = [select id, DeveloperName from RecordType where SObjectType = 'Sample_Transaction__c'];
for (RecordType item : rtList) {
rtMap.put(item.DeveloperName, item);
}
}
return rtMap;
}
}
SampleLotProcessHandler handler = new SampleLotProcessHandler();
handler.initialize(trigger.old, trigger.new, trigger.oldMap, trigger.newMap);
if (trigger.isAfter && trigger.isInsert) {
handler.onAfterInsert();
} else if (trigger.isAfter && trigger.isUpdate) {
handler.onAfterUpdate();
}
}
"update failed Cannot_insert_update_activate_entity samplelotprocess: execution of afterupdate caused by ssytem dmlexception :update failed"
i noticed error shows in line no 82 at the time of update any idea why please advise me
trigger SampleLotProcess on Sample_Lot__c (after insert, after update) {
class SampleLotProcessHandler {
Sample_Lot__c[] oldRows;
Sample_Lot__c[] newRows;
Map<Id, Sample_Lot__c> oldMap;
Map<Id, Sample_Lot__c> newMap;
Map<String, RecordType> rtMap;
public void initialize(Sample_Lot__c[] oldRows, Sample_Lot__c[] newRows, Map<Id, Sample_Lot__c> oldMap, Map<Id, Sample_Lot__c> newMap) {
this.oldRows = oldRows;
this.newRows = newRows;
this.oldMap = oldMap;
this.newMap = newMap;
}
public void onAfterInsert() {
createReceipts();
}
public void onAfterUpdate() {
createReceipts();
}
public void createReceipts() {
Sample_Lot__c[] filteredRows = new Sample_Lot__c[0];
Set<Id> transferIds = new Set<Id>();
for (Sample_Lot__c item : newRows) {
if (item.Status__c != 'Confirmed') continue;
if (oldMap != null && item.Status__c == oldMap.get(item.Id).Status__c) continue;
filteredRows.add(item);
if (item.Original_Transfer_Transaction__c != null) {
transferIds.add(item.Original_Transfer_Transaction__c);
}
}
Sample_Transaction__c[] transfers = [select id, Status__c, Transferred_From__c from Sample_Transaction__c where id in :transferIds];
Map<Id, Sample_Transaction__c> transferMap;
if (transfers.isEmpty()) {
transferMap = new Map<Id, Sample_Transaction__c>();
} else {
transferMap = new Map<Id, Sample_Transaction__c>(transfers);
}
Sample_Transaction__c[] forIns = new Sample_Transaction__c[0];
for (Sample_Lot__c item : filteredRows) {
if (item.Status__c != 'Confirmed') continue;
if (oldMap != null && item.Status__c == oldMap.get(item.Id).Status__c) continue;
Sample_Transaction__c newReceipt = new Sample_Transaction__c();
newReceipt.Transfer_To__c = item.OwnerId;
newReceipt.Comments__c = item.Comments__c;
newReceipt.Quantity__c = item.Confirmed_Quantity__c;
newReceipt.OwnerId = item.OwnerId;
newReceipt.Transfer_To__c = item.OwnerId;
if (transferMap.containsKey(item.Original_Transfer_Transaction__c)) {
newReceipt.Transferred_From__c = transferMap.get(item.Original_Transfer_Transaction__c).Transferred_From__c;
transferMap.get(item.Original_Transfer_Transaction__c).Status__c = 'Confirmed';
}
if (getRtMap().containsKey('Reckitt_Receipt')) {
newReceipt.RecordTypeId = getRtMap().get('Reckitt_Receipt').Id;
}
newReceipt.Product__c = item.Product_ID__c;
newReceipt.Sample_Lot_ID__c = item.Id;
newReceipt.Transaction_Date__c = Date.today();
forIns.add(newReceipt);
}
if (!forIns.isEmpty()) {
insert forIns;
}
if (!transferMap.isEmpty()) {
update transferMap.values();
}
}
public Map<String, RecordType> getRtMap() {
if (rtMap == null) {
rtMap = new Map<String, RecordType>();
RecordType[] rtList = [select id, DeveloperName from RecordType where SObjectType = 'Sample_Transaction__c'];
for (RecordType item : rtList) {
rtMap.put(item.DeveloperName, item);
}
}
return rtMap;
}
}
SampleLotProcessHandler handler = new SampleLotProcessHandler();
handler.initialize(trigger.old, trigger.new, trigger.oldMap, trigger.newMap);
if (trigger.isAfter && trigger.isInsert) {
handler.onAfterInsert();
} else if (trigger.isAfter && trigger.isUpdate) {
handler.onAfterUpdate();
}
}