4

I got a very weird scenario. I was writing a simple trigger on my Case object in Dev ORG. And I have In-Active all trigger on Case and have only 1 before trigger attach to my Case object. I have activated the trigger and create a New case (Insert trigger to work) and later I can see my trigger not functioning as expected, so I check I trigger status and its showing its In-Active.

The same scenario happened 2-3 times, do you know a reason behind it. The trigger is for just populating a Custom Description field (Warranty Summary) based on Custom fields in Case object.

trigger WarrantSummary on Case (before insert) { 
    String endingComment = 'Have a nice Day!!';

    for(Case myCase: Trigger.new){
        if(myCase.Product_Purchase_Date__c != NULL){
            String purchaseDate        = myCase.Product_Purchase_Date__c.format();
            String createdDate         = DateTime.now().format(); 
            Integer warrantyDays       = myCase.Product_Total_Warranty_Days__c.intValue(); 
            Decimal warrantyPer        = (100*(myCase.Product_Purchase_Date__c.daysBetween(Date.today())
                                               /myCase.Product_Total_Warranty_Days__c).setScale(2));
            Boolean hasExtndWrnty      = myCase.Product_Has_Extended_Warranty__c; 

            myCase.Warranty_Summary__c = 'Product purchased on ' +purchaseDate+ 
                ' and case created on ' +createdDate+ '.\n'+
                'Warranty is for ' +warrantyDays+  
                ' Days and is ' +warrantyPer+ '% through its warranty period.\n'+
                'Extended warranty: ' +hasExtndWrnty+ '\n'+    
                endingComment; 
        }
    }
}

Any clue for this? In any chance a Trigger can be automatically In-Active?

7

Are you coding simultaneosly from UI, Devconsole or Force.com IDE? Suppose your trigger was initially deactivated. So if you have activated a trigger via Salesforce UI and that trigger was already open in Dev console. Now when you save in devconsole it will get deactivated again.

Solution: Make trigger Active and Again refresh the Dev Console(Any IDE).

Do you have Continuous Integration in progress, I believe the metadata file isnt updated in your local code, and hence after every commit it makes trigger inactive.

|improve this answer|||||
  • Ya thanks Pranay, it looks like you are correct. I have opened the trigger from UI and Devconsole and might caused the issue. I have closed the UI and can see now all normal. Thanks a lot for your help in this to understand – Robert Thomas Jan 27 '17 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.