You need to sign in to do that
Don't have an account?
Leonardo Girgenti 5
help with testing class
hi there,
could anyone help me with a test class for this trigger?
thanks in advance
trigger MeetingParticipantTrigger on Meeting_Participants__c(before insert){
Set<Id> contactIds = new Set<Id>();
for(Meeting_Participants__c mp : Trigger.new){
contactIds.add(mp.Contact__c);
}
Map<Id,Contact> contacts = new Map<Id,Contact>([Select AccountId From Contact Where Id in :contactIds]);
for(Meeting_Participants__c mp : Trigger.new){
Contact c = contacts.get(mp.Contact__c);
mp.Account2__c = c.AccountId;
}
}
could anyone help me with a test class for this trigger?
thanks in advance
trigger MeetingParticipantTrigger on Meeting_Participants__c(before insert){
Set<Id> contactIds = new Set<Id>();
for(Meeting_Participants__c mp : Trigger.new){
contactIds.add(mp.Contact__c);
}
Map<Id,Contact> contacts = new Map<Id,Contact>([Select AccountId From Contact Where Id in :contactIds]);
for(Meeting_Participants__c mp : Trigger.new){
Contact c = contacts.get(mp.Contact__c);
mp.Account2__c = c.AccountId;
}
}
public static testmethod void test1()
{
Account a = new Account(name ='test account');
insert a;
Contact c = new Contact(name='test contact',account=a);
insert c;
meeting_participants__c mp = new meeting_participants__c(name = 'testmp',contact=c);
insert mp;
system.assertequals(mp.account2__c,c.accountid);
}
i get an error when saving the class.
public static testmethod void test1()
{
Account a = new Account(name ='test account');
insert a;
Contact c = new Contact(AccountId=a.Id,lastname='testing',firstname='apex');
insert c;
meeting_participants__c mp = new meeting_participants__c(name = 'testmp',contact=c);
insert mp;
system.assertequals(mp.account2__c,a.id);
}