Hi i am trying to merge the custom object trigger from sandbox to production. i follow the steps from this site http://www.sfdc99.com/2013/06/04/how-to-deploy-code-from-sandbox-to-production/

when i click the deploy i will get the following error.

Your organization's code coverage is 2%. 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.

This is my trigger

trigger LeadAssignmentTrigger on Broker__c (before insert,before update) 
       List<Broker__c > leadsToUpdate = new List<Broker__c >();
        for (Broker__c broker: Trigger.new)
            if (broker.Referral_ID__c!= NULL)
                String str = broker.Referral_ID__c;
                Integer ln = str.Length();
                String likeStr = '%'+str.subString(ln-10, ln-7)+'%'+str.subString(ln-7, ln-4) +'%'+ str.subString(ln-4);

                // Find the sales rep for the current zip code
                List<User> zip = [select Id from User
                                       where MobilePhone Like : likeStr];

                // if you found one
                if (zip.size() > 0) 
                    //assign the lead owner to the zip code owner
                    broker.OwnerId = zip[0].Id; 
                    // Throw Error
                    broker.addError('Invalid Referrel ID');

and i new to salesforce i don't know how to write test class.

I write the test class,

private class LeadAssignmentTriggerTest 
    static testMethod void validateHelloWorld() 
        Broker__c broker =  new Broker__c();
        //broker.Referral_ID__c = add valid value here
        // Add all required field here

            insert broker;
        Catch(Exception ee)


But i got the same error.What i did error.


1 Answer 1


Write a Test Class for your trigger. And any other classes you have that are not covered as well.

Some help getting started.

Testing is an important part of the development process. Before you can deploy Apex or package it for the Force.com AppExchange, the following must be true.

  • At least 75% of your Apex code must be covered by unit tests, and all of those tests must complete successfully. Note the following.
  • When deploying Apex to a production organization, each unit test in your organization namespace is executed by default.
  • Calls to System.debug are not counted as part of Apex code coverage.
  • Test methods and test classes are not counted as part of Apex code coverage.
  • While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of code that is covered. Instead, you should make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single records. This should lead to 75% or more of your code being covered by unit tests.
  • Every trigger must have some test coverage.
  • All classes and triggers must compile successfully.
  • how to write test class and where i did production or else sandbox
    – Sakthi S
    Mar 29, 2016 at 12:58
  • Write your test code in the same place as you write your other code, sandbox. Please follow the link above on getting some information on how to write the test class. Mar 29, 2016 at 13:01
  • @SakthiS - You can not write code in Production.
    – C0DEPirate
    Mar 29, 2016 at 13:17
  • s,i know that but i dont how to write to test class
    – Sakthi S
    Mar 29, 2016 at 13:20
  • I dont understand how to write apex class for my trigger
    – Sakthi S
    Mar 29, 2016 at 13:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .