You need to sign in to do that
Don't have an account?
Ezmo
Trigger & Test deployment issue
Morning,
I've been having a bit of an issue when trying to deploy a trigger and it's test from a sandbox to production. I've pasted the error and code below, any help or ideas would be much appreciated as this has got me stumped.
Failure Message: "System.QueryException: List has no rows for assignment to SObject", Failure Stack Trace: "Class.TestTriggers.myUnitTest: line 13, column 13 External entry point"
trigger stockControl on Transfer__c (after insert) { for (Transfer__c t : Trigger.new){ if (t.Transfer_Type__c == 'inbound'){ Decimal existingQuantity = 0; Stock_Level__c s = new Stock_Level__c(); try{ s = [SELECT Quantity__c FROM Stock_Level__c WHERE Storage_Area__c = :t.Storage_Area__c AND Resource__c = :t.Resource__c]; existingQuantity = s.Quantity__c; } catch(exception e){ } s.Resource__c = t.Resource__c; s.Storage_Area__c = t.Storage_Area__c; s.Quantity__c = t.Quantity__c + existingQuantity; upsert s; } } }
@isTest private class TestTriggers { static testMethod void myUnitTest() { Transfer__c t = new Transfer__c(); t.Quantity__c = 100000; t.Transfer_type__c = 'inbound'; insert t; Stock_Level__c s = new Stock_Level__c(); s = [SELECT id FROM Stock_Level__c WHERE Quantity__c = 100000]; id i = s.id; insert t; s = [SELECT id FROM Stock_Level__c WHERE id = :i]; System.assert(s.Quantity__c == 200000); } }
Thanks in advance.
Hi,
There are few mistakes in your trigger and test class. I will explain them below.
2. Don't use existing data records in test class. You have fetch some data from Stick_Level__c object. That is wrong.
Here is the guidelines for write your test class
NOTE : These codes for get the idea about your issues. Sometime it will provide errors becuase I'm not aware about your domain
Hope this will help you to resolve your issue.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Chamil's Blog