[SalesForce] Trigger fails because of organization’s code coverage

I recently inherited our Salesforce from a more experienced admin with some developer skills…I am a new admin and have zero developer skills. I need to deploy a trigger that the previous admin wrote which is supposedly ready for deployment. It is supposed to create a project record on our custom Project object whenever an opportunity is closed won. Here is the trigger:

trigger CreateProject on Opportunity (after update) {
    List p = new list(); for (Opportunity O: Trigger.New) if(o.stageName == 'Closed Won')
    { 
        SFDC_Project__c SP = new SFDC_Project__c(); 
        sp.name = 'CLIENT-'; sp.total_charge__C = o.est_monthly_recurring_rev_payspan__c;
        sp.total_charge_reimbursement__c = o.est_monthly_recurring_rev_REI__c; sp.project_type__c = 'Implementation';
        sp.Account__c = O.AccountId; sp.sfdc_project_manager__c = '00550000000n0VZ'; 
        sp.opportunity__c = o.id;
        p.add(sp); 
    } 
    insert p; 
}

The trigger has 100% code coverage in our sandbox environment.

Here are the steps I followed to deploy this (since I am new I may have missed something):

1) Opened the developer console in my Sandbox and ran a test on the trigger which succeeded

2) Went to the Sandbox Outbound Change Sets, and created a new Change Set by clicking New, giving it a name, then adding my trigger to it. I uploaded this to Production successfully.

3) Logged into my Production org, went to inbound change sets, and clicked the name of the change set, then clicked Validate…and got the following errors:

Code Coverage Failure

Your organization's code coverage is 59%. You need at least 75%
coverage to complete this deployment. Also, the following triggers
have 0% code coverage. Each trigger must have at least 1% code
coverage.

UpdateOpportunityId

CreateProject

Details: Test coverage of selected Apex Trigger is 0%, at least 1%
test coverage is required

TestOpportunityLineItem.TestOpportunityLineItem(), Details:
System.DmlException: Insert failed. First exception on row 0; first
error: FIELD_CUSTOM_VALIDATION_EXCEPTION, T8 cannot be greater than
T9: [T8_Qty__c] Class.TestOpportunityLineItem.TestOpportunityLineItem:
line 92, column 1

UpdateOpportunityId, Details: Test coverage of selected Apex Trigger
is 0%, at least 1% test coverage is required

Details: Average test coverage across all Apex Classes and Triggers is
59%, at least 75% test coverage is required.

CreateProject is the name of this trigger, but it has 100% code coverage in the Sandbox so I don't understand why it says it has 0% here.

The next line is referring to a validation rule we have on our products, which doesn't allow certain prices to be more than others, but this trigger has nothing to do with opportunity line items…This other trigger does obviously exist, but it's already been successfully deployed and works…that's not the one I'm trying to deploy here.

I would greatly appreciate any help you can provide! Thank you!

Best Answer

IDs do not carry over from Sandbox to Production. Therefore, it is bad practice to explicitly reference IDs in Apex. In your trigger you have sp.sfdc_project_manager__c = '00550000000n0VZ';.

This is breaking your code.

Related Topic