You need to sign in to do that
Don't have an account?
Trigger Code Coverage
I have a simple trigger with 100% code coverage. In Sandbox all tests are Success. However deploying to prod, I am getting a No Cod eCoverage Error "The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
UpdateOwnerCompany
"
I can see where my error is....what is missing
Here is Trigger Code:
UpdateOwnerCompany
"
I can see where my error is....what is missing
Here is Trigger Code:
trigger UpdateOwnerCompany on Opportunity (before update) { for(Opportunity o :Trigger.new){ User op_owner = [Select u.id, u.CompanyName, u.Company_Code__c from User u where Id =: o.OwnerId]; o.OwnerCompany__c = op_owner.CompanyName; } }Here is the Unit test
@IsTest(seeAllData=false) public class UpdateOwnerCompanyTest { public static Opportunity opt; public static testMethod void testOwner(){ test.startTest(); Profile p = [SELECT Id FROM Profile WHERE Name='Standard Ontario User']; User testuser = new User( Alias = 'cowner', Email='ontariouser@testorg.com', EmailEncodingKey='UTF-8', LastName='Cowner', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, CompanyName = 'TestOntario', TimeZoneSidKey='America/New York', UserName='ontariouser@testorg.com' ); insert testuser; Account testAcct = new Account (Name = 'Test Account'); Date testCloseDate = Date.newInstance(2016, 4, 17); insert testAcct; opt = new Opportunity( Name = 'BuzzCo', AccountId = testAcct.ID, Opportunity_Type__c = 'Existing - SOW', LeadSource = 'Partner', Product_Family__c = 'Test', opportunitie_brands__c = 'Test', StageName = 'Qualification', CloseDate = testCloseDate , Expected_First_Sale_Date__c = testCloseDate.addDays(7), next_step_date__c = testCloseDate ); insert opt; List<Opportunity> insertedOpps = [SELECT OwnerCompany__c FROM Opportunity WHERE name = 'BuzzCo']; for(Opportunity ops : insertedOpps){ User op_owner = [Select u.id, u.CompanyName, u.Company_Code__c from User u where Id =: testuser.Id]; ops.OwnerCompany__c = op_owner.CompanyName; system.debug(ops.OwnerCompany__c); System.assertEquals(ops.OwnerCompany__c, 'TestOntario'); } test.stopTest(); } }
NOTE:- I also found some issue in your Trigger
1) You are using SOQL inside for loop. Update your trigger like below
Let us know if this will help you
All Answers
My guess is that you dont have the test code in production. You should deploy them both to prod.
Hope this helps!
AM
Both the Trigger and the class are in the deployment package already
There are multiple things that looks missing in your trigger and code.
NOTE:- I also found some issue in your Trigger
1) You are using SOQL inside for loop. Update your trigger like below
Let us know if this will help you
Here is the final code that has allowed me to successfully deploy using your suggestions
Thanks