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

Class for trigger to go into production
Hello,
I have 2 triggera into sandbox that work s perfectly and I want to transfer it into production. The only problem is that I need to write a test class for each one in order to cover 75% of the triggers in order to fullfill this. My triggers are
Any ideas would be helpfull. Is there any generic way to do this? Any manuals or anything to study through in order to achieve this (and for future purposes as well)
I have 2 triggera into sandbox that work s perfectly and I want to transfer it into production. The only problem is that I need to write a test class for each one in order to cover 75% of the triggers in order to fullfill this. My triggers are
trigger InsertPriceBookTrigger on Order (before insert) { List<Pricebook2> stdPBL = [select id from Pricebook2 where IsStandard = TRUE]; if(!stdPBL.isEmpty()){ for(Order o: Trigger.new) o.PriceBook2Id = stdPBL[0].id; } }
trigger TaskTrigger on Task (after insert) { List<Order> ordersToUpdate = new List<Order>(); for(Task t : Trigger.new) { if(t.WhatId.getSObjectType() == Order.sObjectType && t.Subject.startsWith('Email:')) { ordersToUpdate.add(new Order(Id = t.WhatId, Status = 'Sent')); } } update ordersToUpdate; }
Any ideas would be helpfull. Is there any generic way to do this? Any manuals or anything to study through in order to achieve this (and for future purposes as well)
The best way to start learning/knowing about test coverages is here:
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Once you go through this, you can try and create test classes for your triggers. And if something acts as a blocker, let us know here.
Good luck!
@isTest
public class My_Test{
public static testmethod void InsertPriceBookTrigger_Test1()
{
Contract c = new Contract(name ='Contract1',status='activated',startdate=system.today(),ContractTerm=12);
insert c;
Order o = new Order(name='Test1',EffectiveDate=system.today(),Contract=c,status='draft');
insert o;
List<Pricebook2> stdPBL = [select id from Pricebook2 where IsStandard = TRUE];
if (!stdPBL.isEmpty())
{
system.assertequals(stdPBL[0].id,o.PriceBook2Id);
}
}
public static testmethod void TaskTrigger_Test1()
{
Contract c = new Contract(name ='Contract1',status='activated',startdate=system.today(),ContractTerm=12);
insert c;
Order o = new Order(name='Test1',EffectiveDate=system.today(),Contract=c,status='draft');
insert o;
Task t = new Task(whatid=o.id,Priority = 'normal',status='open',subject='Email:xxxx');
insert t;
system.assertequals('Sent',o.status);
}
}
Thank you both for your replies.
David as I am really new to this would you please be kind and explain me some basic stuff of the class that you wrote. Thank you in advance
I have inserted the suggested class but the result is 0/2 passed
I don't know if it helps but after reviewing the class I do not have any contracts active since we are using orders without any contracts. I then changed the class into and still failing