function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
travis.truetttravis.truett 

Trigger Won't Deploy (Code Coverage)

I wrote a trigger and a test class for it. The code coverage is 83% in the sandbox. When I try to roll it out, however, I get an error saying my code coverage is only 65% and that I can't deploy. I'm not sure why this is happening...

User-added image

Don't understand why my coverage changes when I go from the sandbox to deployment. I'm someone could help me figure this out, I'd appreciate it. Thanks
Best Answer chosen by travis.truett
SKolakanSKolakan
It is difficult to interpret without looking at the actual code but here is my 2c.

In your trigger it looks like you are assigning result of a SOQL query to an object like

CustomObject__c obj = [Select Id,Field1__c From CustomObject__c Where ....];

When the query does not return any results, it throws error like that. If you have some thing like that, change it to

List<CustomObject__c> objs = [Select Id,Field1__c From CustomObject__c Where ....];

 

All Answers

Vivek DeshmaneVivek Deshmane
Hi Travis,
Once you fix this error then coverage will get increased automatically.

Best Regads,
-Vivek
Vivek DeshmaneVivek Deshmane

Hi Travis,

Do you have same code replca of production  in sandbox then do runall test in sandbox .
You should get same error and it's easy to fix .

Best Regards,
-Vivek
travis.truetttravis.truett
I ran all of my test classes in the sandbox, and two of them, which were previously working correctly, threw errors. I'm not sure how to proceed in order to correct this.

Class testEditSchedule
Method Name testUpdateSchedule
Pass/Fail Fail
Error Message System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []
Stack Trace Class.testEditSchedule.testUpdateSchedule: line 46, column 1

Class ZendeskUtilitiesTests
Method Name ticketCreated
Pass/Fail Fail
Error Message System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Create_followup: execution of AfterInsert
caused by: System.QueryException: List has no rows for assignment to SObject
Trigger.Create_followup: line 2, column 1: []
Stack Trace Class.ZendeskUtilitiesTests.createOpportunity: line 29, column 1
Class.ZendeskUtilitiesTests.ticketCreated: line 34, column 1
SKolakanSKolakan
It is difficult to interpret without looking at the actual code but here is my 2c.

In your trigger it looks like you are assigning result of a SOQL query to an object like

CustomObject__c obj = [Select Id,Field1__c From CustomObject__c Where ....];

When the query does not return any results, it throws error like that. If you have some thing like that, change it to

List<CustomObject__c> objs = [Select Id,Field1__c From CustomObject__c Where ....];

 
This was selected as the best answer
travis.truetttravis.truett
that was exactly the problem. Thanks!