+ Start a Discussion
Laxmaya ChnLaxmaya 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;
    }
}
Best Answer chosen by Laxmaya Chn
deepak balur 19deepak balur 19
Is Phone, Electronics & Accessories a valid value for the Category picklist? Please add this value to your picklist.
 

All Answers

deepak balur 19deepak balur 19
Is Phone, Electronics & Accessories a valid value for the Category picklist? Please add this value to your picklist.
 
This was selected as the best answer
SalesFORCE_enFORCErSalesFORCE_enFORCEr
I think "Strictly enforce picklist values" checkbox is checked on the picklist field and you are trying to populate this field with such picklist values which are not defined on the field level.