You need to sign in to do that
Don't have an account?
Roopa S 1
hi have written this trigger to calculate discount but while saving getting error anybody plz suggest ur solutions
this is the error im getting while saving the code.
Failed to create createContainerMember for containerId=1dc5f000001ETl9AAG: duplicate value found: MetadataContainerId duplicates value on record with id: 4015f000000pZWq, MetadataContainerId duplicates value on record with id: 4015f000000pZWq
trigger bookTrigger on Books__c (after insert) {
list<Books__c> listOfBooks1 = new list<Books__c>();
list<Books__c> listOfBooks = new list<Books__c>();
Set<ID> setOfId = new Set<ID>();
for(Books__c book: Trigger.New){
setOfId.add(book.Id);
}
listOfBooks = [SELECt Id,Price__c FROM Books__c WHERE Id IN:setOfId];
if(listOfBooks.size()>0){
for(Books__c book: listOfBooks){
book.Price__c = book.Price__c - (10/100)*book.Price__c;
listOfBooks1.add(book);
}
}
if(listOfBooks1.size()>0){
update listOfBooks1;
}
}
Failed to create createContainerMember for containerId=1dc5f000001ETl9AAG: duplicate value found: MetadataContainerId duplicates value on record with id: 4015f000000pZWq, MetadataContainerId duplicates value on record with id: 4015f000000pZWq
trigger bookTrigger on Books__c (after insert) {
list<Books__c> listOfBooks1 = new list<Books__c>();
list<Books__c> listOfBooks = new list<Books__c>();
Set<ID> setOfId = new Set<ID>();
for(Books__c book: Trigger.New){
setOfId.add(book.Id);
}
listOfBooks = [SELECt Id,Price__c FROM Books__c WHERE Id IN:setOfId];
if(listOfBooks.size()>0){
for(Books__c book: listOfBooks){
book.Price__c = book.Price__c - (10/100)*book.Price__c;
listOfBooks1.add(book);
}
}
if(listOfBooks1.size()>0){
update listOfBooks1;
}
}
Please try this.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
As you are trying to update the field on the book you need to use before Insert context. Please modify the code as below.
If this solution helps, Please mark it as best answer.
Thanks,
Please try this.
If this solution helps, Please mark it as best answer.
Thanks,