1

i have a code for trigger:

trigger SendDisbursement on Opportunity (after update) {
if (!System.isFuture()){
    for (Integer i = 0; i < Trigger.new.size(); i++) {
        if (Trigger.old[i].StageName != Trigger.new[i].StageName && Trigger.new[i].StageName == 'Disbursement' && Trigger.new[i].RecordTypeId == '12903903930390') {
            Organization org = [SELECT IsSandbox FROM Organization];
            String orgStr = (org.IsSandbox == true) ? 'sale' : 'credit';
            EmailUtil.mailSender(Trigger.new[i], orgStr);
        }
    }
}
}

when i try deploy on production i get the message:

Your code coverage is 0%. You need at least 75% coverage to complete this deployment. enter image description here

  • Does this answer your question? How do I write an Apex unit test? – David Cheng Jan 16 at 3:04
  • Did you deploy your test class as well in the change set? It says only deploying 1 component. If you're deploying this for the first time to production, you'll need to include the trigger and the unit test class – Brian Miller Jan 16 at 7:59
4

To deploy a trigger to production , you will need to ensure your trigger has a test class and the class needs to cover at least 75% of the lines of code .

Looks like you are writing the trigger for first time .

I suggest you go through Salesforce trailhead content and learn some of the best practices such as below

  1. bulkify your trigger

  2. do not write soql or dml inside loop

  3. Have a trigger framework for the project to manage complexity and help easy debugging
  4. Ensure proper test code coverage with system asserts

Check the below link on how to write test case for a trigger

https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_triggers

  • Hello, when i upload without check "isActive" work fine deployment, but when i check the "isActive" get a error on deploy, is for any reason? – pedroooo Jan 16 at 0:45
  • Have you written the test class ? You will need a test class as well to deploy with the trigger – Mohith Shrivastava Jan 16 at 1:33
  • i update the question with the apex class code when i try run the code i get a: "Methods defined as TestMethod do not support Web service callouts" – pedroooo Jan 16 at 4:11
  • Looks like you have a third party web service callout using http class.I suggest look into Salesforce mocks for same . – Mohith Shrivastava Jan 16 at 12:41
0

From your last updated comment it seems that you have run the test method but your hackClipDisburse() which is called is not having isTest qualifier I only see one on class.

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.