You need to sign in to do that
Don't have an account?
cathy369
Test trigger that uses custom object with one record to get order number
I've got a very simple trigger that retrieves a unique order number from a custom object. The reason for the trigger is the Order Number is used by 2 different objecsts. Below is the trigger and associated class... As you can see, the object only has one record named "ORDER", which is how I retrieve it. It works fine in test, but I'm not sure how to write my test class. If I create a record in the object, then it will have 2 'ORDER' records.
I'm kind of at a loss.
Any help would be greatly appreciated...Thanks much.
I'm kind of at a loss.
Any help would be greatly appreciated...Thanks much.
trigger getOrdNum on Opportunity (before insert) { for (Opportunity o : Trigger.new){ o.Test_SF_Ord_Num__c = orderNumber.getOrderNumber(); } } ________________________________________ Class: public class orderNumber { public static decimal getOrderNumber(){ List<Order_Number__c> ListOrderNum = [SELECT Order_Num__c FROM Order_Number__c WHERE Name = 'ORDER']; if( ListorderNum.size() > 0 ) { ListorderNum[0].Order_Num__c += 1; update ListOrderNum[0]; return ListOrderNum[0].Order_Num__c; } return 0; } }
The records created in testmethod are stored in testdata not in your organization.
testmethods do not have access to your organization data unless you specify @isTest(SeeAllData=true) in your test class,
try the below code.
Mark it as the best answer if it helps,
Thanks,
Balayesu