function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Leonardo Girgenti 5Leonardo Girgenti 5 

Help with a test class

Can anyone help me to write the Test Class for this Trigger?
I am not skilled to write it up so really need help. Thanks


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;

    }
}
ManojjenaManojjena
Hi Leonardo ,

Hey I am not sure which all are mandatory fields in your objects .

So here is the basic code of test class 

@isTest
public class MeetingParticipantTrigger Test{
   static testMethod void unitTest(){
      //Create one account 
        Account acc= new Account();
            acc.Name ="TestAccount";
            Insert acc;
       Contact con=new Contact();
                 con.lastName="Test";
                 con.AccountId=acc.Id;
       Meeting_Participants__c  metpt=new Meeting_Participants__c();
          metpt.Contact__c=con.Id;
       //Give all mandatory fields in your Meeting_Participants object 

     Insert metpt;

  //Don't forget to add System.assert /assertEqual /assertNotEqual in each Dml atleast .

Let me know any issue .

  }
}
Leonardo Girgenti 5Leonardo Girgenti 5
Thanks.
I will try but I dont think I understand "
Don't forget to add System.assert /assertEqual /assertNotEqual in each Dml atleast".