You need to sign in to do that
Don't have an account?
Daniel B Probert
Test Class for Trigger Help
Hi Guys,
I've written a very simple trigger for Campaigns that works well however, I want to ensure I have a test class for it and haven't written a test class before.
This is my trigger:
rigger createjournalcodes on Campaign (after insert) { List<Journal_Codes__c> journalcodes = new List<Journal_Codes__c>(); for (Campaign camp : trigger.new) { Journal_Codes__c jc = new Journal_Codes__c(); jc.Campaign__c = camp.Id; jc.CurrencyIsoCode = 'GBP'; jc.L1_Country_Region__c = 'UK'; jc.L1_Country_Region_Display__c = 'United Kingdom'; jc.L2_Activity_Codes__c = 'U'; jc.L2_Activity_Codes_Display__c = 'Unallocated'; jc.L3_Donor_Codes__c = 'CAMFE'; jc.L4__c = 'UREST'; jc.L5_Database_Code__c = 'CAM'; journalcodes.add(jc); } for (Campaign camp : trigger.new) { Journal_Codes__c jc = new Journal_Codes__c(); jc.Campaign__c = camp.Id; jc.CurrencyIsoCode = 'USD'; jc.L1_Country_Region__c = 'US'; jc.L1_Country_Region_Display__c = 'United States'; jc.L2_Activity_Codes__c = 'U'; jc.L2_Activity_Codes_Display__c = 'Unallocated'; jc.L3_Donor_Codes__c = 'CAMFE'; jc.L4__c = 'UREST'; jc.L5_Database_Code__c = 'USA'; journalcodes.add(jc); } insert journalcodes; }
so i'm guessing I need a test class that creates a campaign but then I'm stuck on what I should be doing from there.
I have some required fields on the campaign so I'm guessing it needs to have them in there but then do I also need to create these related items or what?
confused myself a bit :)
cheers
dan
@IsTest
public class CampaignTestCLass
{
public static testmethod void CampaignTestMethod()
{
Campaign campaign = new Campaign();// mention the required fields and do insert
insert campaign;
}
}
All Answers
@IsTest
public class CampaignTestCLass
{
public static testmethod void CampaignTestMethod()
{
Campaign campaign = new Campaign();// mention the required fields and do insert
insert campaign;
}
}
so simple i was really over thinking it good man cheer..