function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pallavic14Pallavic14 

Custom object trigger works in sandbox not in production

Hi,
PLease help.
I have a custom object and a trigger, I see its working in sandbox , with test case coverage of 100% i migrated to production. This trigger is not working.
is there anything to do special for custom triggers?
 when a field is updated , oan custom object record is created with a trigger, after record is created I want opportunity object to be updated back.

Here is the code
trigger UpdateRefExist on Customer_Ref_Design__c (after insert) {
List <Opportunity> oppupdate = new List <Opportunity>();
    for (Customer_Ref_Design__c ref : Trigger.new){
        Opportunity opp = [select Id,RefDesignExist__c from Opportunity where Id = :ref.Oppid__c]; 
        opp.RefDesignExist__c='Y';  
           oppupdate.add(opp);
        }
     try {
         update oppupdate;
         } catch (system.Dmlexception e) {
             system.debug (e);
         }
}

Thanks
Pallavi
Pramodh KumarPramodh Kumar
1. see the debug log does the trigger is getting fired or not.
2. see the inserted Customer_Ref_Design__c having the opportunity id. If opportunity id is not available then the query will be null.

Let me know if you find any other solution.
 
Kunal01Kunal01
Hi Pallavi,

1. Check if the trigger is active in PROD.
2. Please bulkify the trigger.

trigger UpdateRefExist on Customer_Ref_Design__c (after insert) {
    List <Opportunity> oppupdate = new List <Opportunity>();
    set<Id> oppIdSet = new set<Id>();
    for (Customer_Ref_Design__c ref : Trigger.new){
        if(ref.Oppid__c != null)
            oppIdSet.add(ref.Oppid__c);
    }
    if( Opportunity opp : [select Id,RefDesignExist__c from Opportunity where Id IN:oppIdSet]){
        opp.RefDesignExist__c='Y';  
        oppupdate.add(opp);
    }    
        
     try {
         update oppupdate;
         } catch (system.Dmlexception e) {
             system.debug (e);
         }
}


Thanks,
~KR
Pallavic14Pallavic14
Yes, trigger is fired. I see it is returning 1 row with the id. Any other ideaas? Regards, Pallavi Chennoju
Pallavic14Pallavic14
HI Kunal, Thank you for reply. I tried bulkifying. I don’t see its working still and no errors in log. Any other ideas? Regards, Pallavi Chennoju
Pallavic14Pallavic14
This is my frist time Trigger on Custom object. Does trigger need to be anything differnet for custom object?
Kunal01Kunal01
Check if there is any exception coming while updating opportunity. Seems like there is some exception whilke updating opportunity. And to answer on your trigger question. Trigger is same for standard and custom objects.

~KR  
Pallavic14Pallavic14
HI Kunal, Exception was before the trigger fired, so I ignored before. But I had to adjust my validation rule which was causing this problem. Still I don’t understand with same validation rule trigger was working fine in sandbox but not live. Anyways. Thank you very much for response. Regards, Pallavi Chennoju