doing a unit test case on a case trigger and getting results that indicate the new case gets created, but not the new contacts. None of the created contact info gets propagated through but the case info does....not sure whats going on any help?
Here is my unit test case
@istest public class TriggerTest
{
public static testMethod void myTest()
{
List<string> ids = new List<string>(); //more for debugging
for(integer i=0; i<20; i++)
{
//create some contacts first-tried creating contacts with in case creation loop below but that didn't work either...
string em='joe'+string.valueof(i)+'@gmail.com';
string last = 'joe'+string.valueof(i);
System.Debug('triggerTest:email:'+em);
Contact cont = new contact(email=em,lastname=last);
Since you are inserting the record in your test method .So you have to make query on your test record inside the trigger code to get the email , lastname value of contact. Thy the below code as reference: trigger trig on Case (before insert) { List<TriggerTest__c> tt = new List<TriggerTest__c>(); for(case c:trigger.new) { System.Debug('trig:origin:'+c.origin); System.Debug('trig:status:'+c.status); System.Debug('trig:contactId:'+c.contactid); contact cou=[select email,lastname,id from contact where id=:c.contactid]; system.debug('################' +cou.email);
Hi,
Since you are inserting the record in your test method .So you have to make query on your test record inside the trigger code to get the email , lastname value of contact. Thy the below code as reference:
trigger trig on Case (before insert)
{
List<TriggerTest__c> tt = new List<TriggerTest__c>();
for(case c:trigger.new)
{
System.Debug('trig:origin:'+c.origin);
System.Debug('trig:status:'+c.status);
System.Debug('trig:contactId:'+c.contactid);
contact cou=[select email,lastname,id from contact where id=:c.contactid];
system.debug('################' +cou.email);
System.Debug('trig:name:'+cou.lastname);
System.Debug('trig:email:'+cou.email);
tt.Add( new TriggerTest__c(EntryTime__c = datetime.now(), Email__c= 'j@email.com'));
}
if(!tt.isempty())
{
insert tt;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.