You need to sign in to do that
Don't have an account?

Don't know how to write test class for trigger
I have wrote some triggers in sandbox, but I don't know how to write test class for trigger?
This is one of my trigger, very simple,
trigger Accountchecking on Account (before insert) {
if (Trigger.new[0].Name != NULL && Trigger.new[0].group__C != NULL && Trigger.new[0]. BillingCountry != NULL) {
Account[] acc = [ select id from account WHERE name = :Trigger.new[0].Name and group__C=: trigger.new[0].group__C and BillingCountry =:Trigger.new[0].BillingCountry];
if (acc.size() > 0) {
Trigger.new[0].Name.addError('Account Name ,Group and Country cannot be repeated!');
}
}
}
So, I should write one test class in apex, and then the trigger can be seen in org?
Great Thanks
Here is your code
Use this one instead of earlier
Just a FYI my dear friend, you can edit your previous reply.
Perhaps you can assist me with my test class as well? Here is my trigger.
The object this is on is the dsfs__DocuSign_Status__c object. Enveloper # is the only required field
trigger is:
trigger DeliverySeasonalBeforeUpdateTrigger on Delivery_Seasonal__c (before insert, before update) {
List<Delivery_Seasonal__c> deliverySeasonals= Trigger.new;
Vaccine_Ordering_Form__c vaccine_Ordering_Form=null;
for (Delivery_Seasonal__c delivery_Seasonal :deliverySeasonals) {
vaccine_Ordering_Form=[select CustomerType123__c, Product_Area__c,Order_Type__c,Total_Order_Value__c from Vaccine_Ordering_Form__c where id=:delivery_Seasonal.DeliverySeasonal__c];
if(vaccine_Ordering_Form.Order_Type__c == 'In-Season' || vaccine_Ordering_Form.Order_Type__c == 'Seasonal'){
vaccine_Ordering_Form.Order_Type__c = 'None';
}
Pricing_Model__c[] pricingModels=[select id from Pricing_Model__c where
Product__c=:delivery_Seasonal.Product__c and
Customer_Type__c=:vaccine_Ordering_Form.CustomerType123__c and
Product_Area__c=:vaccine_Ordering_Form.Product_Area__c and
Order_Type__c=:vaccine_Ordering_Form.Order_Type__c and
(
//Order_Volume__c='NA' or
(Order_Volume_Higher_Limit__c=null and Order_Volume_Lower_Limit__c=null) or
(Order_Volume_Higher_Limit__c=null and Order_Volume_Lower_Limit__c<=:delivery_Seasonal.Total__c) or
(Order_Volume_Lower_Limit__c<=:delivery_Seasonal.Total__c and Order_Volume_Higher_Limit__c>=:delivery_Seasonal.Total__c)
)];
String newPricingModel=null;
if(!pricingModels.isEmpty()){
newPricingModel=pricingModels[0].id;
}else{
delivery_Seasonal.addError('No Pricing Model found. Please put correct Product detail & Order Volume.');
}
if(delivery_Seasonal.price__c!=newPricingModel){
delivery_Seasonal.price__c=newPricingModel;
//update delivery_Seasonal;
}
}
}