You need to sign in to do that
Don't have an account?
Sam Epstein
Fixing Code Coverage on Apex Trigger
Hello,
I am trying to deploy this apex trigger from sandbox to production but keep getting this error:
Your organization's code coverage is 74%. 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.
I'm wondering what would be the best way to increase the code coverage with my trigger below. This trigger is used with Dropbox. Any help would be so appreciated!
I am trying to deploy this apex trigger from sandbox to production but keep getting this error:
Your organization's code coverage is 74%. 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.
I'm wondering what would be the best way to increase the code coverage with my trigger below. This trigger is used with Dropbox. Any help would be so appreciated!
trigger Dropbox_Trigger_Vendor on Vendor__c (after update, after delete) { if(Trigger.isAfter && Trigger.isUpdate){ Dropbox_for_SF.HandleRecordChange.OnRecordChange(Trigger.old, Trigger.new); } if(Trigger.isAfter && Trigger.isDelete){ Dropbox_for_SF.HandleRecordChange.HandleMerge(Trigger.old); } }
Use this test class:
@isTest
public class CustomTest
{
static testMethod void updateVendor() {
<Vendor__c> a = new <Vendor__c> (Name='test');
insert a;
Test.startTest();
a.Name = 'new test';
update a;
Test.stopTest();
system.assertEquals('new test', a.name);
}
}
Thanks,
Ajay Dubedi
All Answers
Your trigger is on after update and delete context.So please update or delete any record in your test class. thn it will work.
Thanks
In the case of the test class for the trigger, you need to perform some DML operations in the test class as in your case 'after update, after delete'
you need to first create a record of Vendor__c and then update this and for cover delete part delete this record.
For the test class for trigger follow this link:
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_triggers
http://www.sfdcpoint.com/salesforce/test-class-with-example-salesforce/
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Thank you for your response. So I'm following instructions from Dropbox (https://help.dropbox.com/installs-integrations/third-party/salesforce-advanced) and they said to use the following code as a custom Apex Class with the name CustomTests in the custom change set:
When saving, I get these errors:
Any idea how to resolve this??
Thanks for all your help!
Use this test class:
@isTest
public class CustomTest
{
static testMethod void updateVendor() {
<Vendor__c> a = new <Vendor__c> (Name='test');
insert a;
Test.startTest();
a.Name = 'new test';
update a;
Test.stopTest();
system.assertEquals('new test', a.name);
}
}
Thanks,
Ajay Dubedi
please update your method declartion. You cannot use keywords and object Api for method names. so just do one update in you method.>