You need to sign in to do that
Don't have an account?
Laxmaya Chn
Getting Error while updating a record in opportunity in an after update trigger
Hi I have writter a trigger for updating child object(CTOpportunity__c) records if there is an update in opportunity(parent) record then the related field should update in the child record(CTOpportunity__c object). While saving the record, It's giving the following error (Update failed. First exception on row 0 with id a0dP0000000S6tRIAS; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Category: bad value for restricted picklist field: Phone, Electronics & Accessories: [Category__c]: Trigger.Intg_Opty_Update: line 29, column 1) here field Category__c is picklist . What might be the cause?. Thanks in Advance.
Trigger Code
trigger CTOpty_Update on Opportunity(after update) {
set<Id> OptIds = new set<Id>();
map<Id, Opportunity> mapOpty = new map<Id, Opportunity>();
List<CTOpportunity__c> lstIntgopt = new List<CTOpportunity__c>();
for(Opportunity Opt : Trigger.New) {
OptIds.add(Opt.Id);
mapOpty.put(Opt.Id, Opt);
}
lstctopt = [SELECT Name, Amount__c, Total__c,Category__c,Commission__c,
Opportunity__c FROM CTOpportunity__c WHERE Opportunity__c IN: OptIds];
if(lstctopt.size() > 0) {
for(CTOpportunity__c ctop : lstIntgopt) {
ctop.Amount__c = mapOpty.get(ctop.Opportunity__c).Amount__c;
ctop.Total__c = mapOpty.get(ctop.Opportunity__c).Total__c;
ctop.Category__c = mapOpty.get(ctop.Opportunity__c).Category__c;
ctop.Commission__c = mapOpty.get(ctop.Opportunity__c).Commission__c;
}
update lstctopt;
}
}
Trigger Code
trigger CTOpty_Update on Opportunity(after update) {
set<Id> OptIds = new set<Id>();
map<Id, Opportunity> mapOpty = new map<Id, Opportunity>();
List<CTOpportunity__c> lstIntgopt = new List<CTOpportunity__c>();
for(Opportunity Opt : Trigger.New) {
OptIds.add(Opt.Id);
mapOpty.put(Opt.Id, Opt);
}
lstctopt = [SELECT Name, Amount__c, Total__c,Category__c,Commission__c,
Opportunity__c FROM CTOpportunity__c WHERE Opportunity__c IN: OptIds];
if(lstctopt.size() > 0) {
for(CTOpportunity__c ctop : lstIntgopt) {
ctop.Amount__c = mapOpty.get(ctop.Opportunity__c).Amount__c;
ctop.Total__c = mapOpty.get(ctop.Opportunity__c).Total__c;
ctop.Category__c = mapOpty.get(ctop.Opportunity__c).Category__c;
ctop.Commission__c = mapOpty.get(ctop.Opportunity__c).Commission__c;
}
update lstctopt;
}
}
All Answers