I am very thick when it comes to setting up test classes. How to set up a test class for a very simple trigger like this?
trigger trgr_Key_People on Key_People__c (after insert, after update, after delete) {
Map<Id, Account> m = new Map<Id, Account>();
if(Trigger.isInsert || Trigger.isUpdate)
{
// Find the parent contacts
for (Key_People__c rsp: Trigger.new)
{
m.put(rsp.Account__c, new Account(
Id = rsp.Account__c,
Key_People__c = ''
));
}
}else if (Trigger.isDelete)
{
for (Key_People__c rsp: Trigger.old)
{
m.put(rsp.Account__c, new Account(
Id = rsp.Account__c,
Key_People__c = ''
));
}
}
String fontColor = 'blue';
// Query all child objects and re-build the text in the parent contacts
for (Key_People__c rsp : [
Select Account__c, first_name__c, last_name__c, portfolio__c,email__c,phone__c,title__c
from Key_People__c
where Account__c in :m.keySet()
order by CreatedDate
]) {
Account c = m.get(rsp.Account__c);
c.Key_People__c += rsp.first_name__c + ' ' + rsp.last_name__c + '<span style="color:'+fontColor+'; font-weight: bold;"> '+ ' ' + rsp.portfolio__c + '</span> '+ '<br />';
}
update m.values();
}
This is my attempt at setting up data. I haven't gotten that correct without errors. It doesn't like my recordtype. I get the error "Invalid initial expression type for field RecordType, expecting: RecordType (or single row query result of that type)"
@isTest
public class test_BOG_Committee_Report {
static testMethod void test_BOG_Committee_Report()
{
Account a1 = new Account(Name='AccountTest1',RecordType='01220000000MFXn');
Account a2 = new Account(Name='AccountTest2',RecordType='01220000000MFXn');
Account a3 = new Account(Name='AccountTest3',RecordType='01220000000MFXn');
Contact c1 = new Contact(Name='ContactTest1',RecordType='01220000000MEBo',Constituent_Code__c='Donor',Account='AccountTest1');
Contact c2 = new Contact(Name='ContactTest2',RecordType='01220000000MEBo',Constituent_Code__c='Donor',Account='AccountTest2');
Contact c3 = new Contact(Name='ContactTest3',RecordType='01220000000MEBo',Constituent_Code__c='Donor',Account='AccountTest3');
BOG_Membership__c bm = new BOG_Membership__c(Contact__c='ContactTest1', RecordType='01220000000MEHG');
// Insert
insert bm;
// Retrieve
bm = [SELECT Contact__c FROM BOG_Membership__c WHERE Id =:bm.Id];
Test.startTest();
Test.stopTest();
}
}