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

afterupdate error
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();
}
}
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();
}
}
However, you need perfect your transferMap preparation logic to work with your Lookup filter output.
You may want to put some debug statements in the code which reads and writes to transferMap map object to see where exactly the road block is.
Hope this helps.
All Answers
And, please post your Trigger and Helper classes in different code blocks, so that it will be easy for us to debug.
when user login we load the below VF and
user get the below screen and when user click the confirm button the popup screen open and then he click confirm button in popup then
calling below trigger in an object
and got error like below any idea why
please advise me
thanks
soma
From the error screen shot, I believe that this error is caused by either a Validation Rule or a Lookup Filter set on the Sample_Lot__c object.
Can you check if there is a validation rule that shows a message like "Only confirmed Sample Lots are available"?
yes one of the field uses below lookup , once i disbale filter it works fine but what could be the best solution without disbale the lookup filter
((Sample Transaction: Record TypeequalsReckitt Transfer, Reckitt Return) and (Sample Lot: StatusequalsConfirmed) and (Sample Lot: Owner IDequalsCurrent User: User ID)) or (Sample Transaction: Record Typenot equal toReckitt Return, Reckitt Transfer)
However, you need perfect your transferMap preparation logic to work with your Lookup filter output.
You may want to put some debug statements in the code which reads and writes to transferMap map object to see where exactly the road block is.
Hope this helps.