I am learning how to write unit tests for my email trigger. I want to test it with 100 emails, please see comments in code.
public static testMethod void testEmail() {
User u1 = [SELECT Id FROM User WHERE profileID IN (SELECT id FROM Profile WHERE Name = 'System Administrator') AND IsActive = true LIMIT 1];
System.RunAs(u1) {
ApexTrigger myTrigger = [SELECT Id, Status FROM ApexTrigger WHERE name = 'EmailTrigger'];
Boolean isActive = (myTrigger.Status == 'Active');
//here I am now inserting 100 contacts
for (Integer count = 0; count++; count < 100) {
insert new Contact [] { new Contact (FirstName = 'John'+count, LastName ='Doe'+count) };
}
//now this is where the problem occurs, I now need to create my patients, which lookup
//my contacts, but how do I do that?
//to create a single patient, I would write:
Patient__c p = new Patient (Description = 'descr', Contact__c = 'not sure how to assign from above');
insert p;
}
}
Does this make sense? So, I know how to create 100 contacts, but I do not know how to create the 100 patients. Let's just say that each patient maps to exactly one contact. How would I do that? TIA.
INVALID_FIELD_FOR_INSERT_UPDATEorCANNOT_INSERT_UPDATE_ACTIVATE_ENTITY. It sounds like there is a problem somewhere within your trigger code, which likely means it is outside of the scope of this question. This should help you out: http://salesforce.stackexchange.com/questions/36582/how-do-i-start-to-debug-my-own-apex-code – Alex Tennant Jun 23 '14 at 10:19