+ Start a Discussion
jalexanderjalexander 

How to deactivate (or delete) an old, unused third-party trigger w/o any test code?

We have migrated to a new CPQ package in Salesforce, but have an old, unsupported trigger that is causing problems with creating new Opportunities. I deactivated the trigger in my Sandbox, pushed it out in a change set, but it fails in the Production Org because there is no test class?

I have no idea how to write the test class, and have no access to the old third-party support. 

Here is the trigger:
//This is provided as a sample to require a contact on opportunities it is provided without warranty and support. 

trigger opportunity_contact_required on Opportunity (before insert, before update) {
/*
    //map to keep track of the contact_required = 1
    Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

    //Trigger.new is an array of opportunities 
    //and adds any that have Contact_Required = 1 to the oppy_contact Map
    for (Integer i = 0; i < Trigger.new.size(); i++) {
        System.debug('*****Required? ' + Trigger.new[i].contact_required__c);
        if  (Trigger.new[i].contact_required__c == 1) {
            oppy_contact.put(Trigger.new[i].id,Trigger.new[i]);
        }  
    }

    //map to keep track of the opportunity contact roles
    map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();

    //select OpportunityContactRoles for the opportunities with contact role required 

    List<OpportunityContactRole> roles = [select OpportunityId, IsPrimary from OpportunityContactRole
        where (OpportunityContactRole.IsPrimary = True and OpportunityContactRole.OpportunityId
        in :oppy_contact.keySet())];


    for (OpportunityContactRole ocr : roles) {
        //puts the contact roles in the map with the Opportunity ID as the key
        oppycontactroles.put(ocr.OpportunityId,ocr);
    }

    // Loop through the opportunities and check if they exists in the contact roles map or contact role isn't required    
    for (Opportunity oppy : system.trigger.new) {
        //system.debug('List oppy Id - '+oppy.id);
        if  (oppy.contact_required__c ==1 && !oppycontactroles.containsKey(oppy.id))
        {
            oppy.addError('No Primary Contact Exists. Please go to the Contact Roles and select a primary contact.  Insure that all contacts related to this Opportunity are properly added in the Contact Roles with respective roles assigned.');       
        }
    } //for    */
 }

Here is the error: http://screencast.com/t/2V9hnkTH1 
User-added image
Best Answer chosen by jalexander
PavanKPavanK
Hi,
I will suggest two option, if trigger is not a part of managed packaged

1) Do not comment trigger code
    Deactivate trigger and deploy(As you said you dont require trigger code)

2) Create desctructive file and deploy with Ant which will delete trigger from production

All Answers

PavanKPavanK
Hi,
I will suggest two option, if trigger is not a part of managed packaged

1) Do not comment trigger code
    Deactivate trigger and deploy(As you said you dont require trigger code)

2) Create desctructive file and deploy with Ant which will delete trigger from production
This was selected as the best answer
jalexanderjalexander
Thanks for the reply..
- Regarding deactivating: The trigger is not managed but as mentioned, my change set will not deploy because of errors listed above?
- Regarding creating a destructive file, will ANT get around the errors listed above?
jalexanderjalexander
Thankfully, I was able to deactivate the old triggers by deploying the "test class" along with the trigger (I realized the test class was in a separate file)
  • I created a new Outbound Change Set
  • Included both the trigger and the class
  • Then deployed in production choosing to use "only" that test class
This time, the test succeeded and the triggers were deactivated.
PavanKPavanK
Great to hear.

Thanks for marking answer as best