You need to sign in to do that
Don't have an account?
Creating a custom object record based upon opportunity trigger
Okay I'm graduating from using triggers for simple field updates to creating a new record of a custom object. I need help getting the test class to work and the trigger as well.
When an opportunity is won (designated as the status being Closed Won), I want to create a new Checklist (custom object) with the required fields of the name being static text, a template ID being designated, the account referenced via the Entity lookup field, and a deadline set 10 days from today.
Here's the trigger so far.
trigger OpportunityChecklist on Opportunity (after update) { if (Trigger.new.size() == 1) { if (Trigger.old[0].StageName != 'Closed Won' && Trigger.new[0].StageName == 'Closed Won') { L5CL__Checklist__c obj = new L5CL__Checklist__c(); obj.Name = 'New Agency Orientation'; obj.L5CL__Checklist_Template__c = 'a18A0000000GvAG'; obj.L5CL__Entity__c = Trigger.new[0].AccountId; date now = date.today(); obj.L5CL__Deadline__c = now.addDays(10); insert obj; } } }
As for the test class, I'm not exactly sure how the system.assertequals function should be written to reference the newly created custom object record.
@isTest private class OpportunityWonChecklistTest { static testMethod void myUnitTest() { Test.startTest(); Opportunity o = new Opportunity(); o.name='NA'; o.RecordTypeId='012A0000000L9p0'; o.Type = 'Deferred Annuity'; o.StageName = 'Engage'; o.CloseDate = date.today(); insert o; o.StageName = 'Closed Won'; update o; L5CL__Checklist__c l_new = ???????; system.assertequals(l_new.Name != null, l_new.Name); Test.stopTest(); } }
Thanks for the help. This is starting to make sense.