+ Start a Discussion
Patrick/ JamesPatrick/ James 

Test classes - Rich Text Fields - Cross-object

Hi there,

It's worth stating that I'm extremely new to APEX trigger writing - so apologies for the inexperience.

We've written the following trigger in Sandbox -
 
trigger RichText1 on CampaignMember (before insert, before update) {
Set<Id> camIdSet=new Set<Id>();
  for(CampaignMember camm: Trigger.new){
   camIdSet.add(camm.CampaignId);
 }
 Map<Id,Campaign> camMap=new Map<Id,Campaign>([SELECT Id,Extra_Info_for_Reminder__c FROM Campaign WHERE Id IN :camIdSet]);
 for(CampaignMember campMem: Trigger.new){
   if(campMem.CampaignId != null ){
     campMem.Course_Email_Info_2__c=camMap.get(campMem.CampaignId).Extra_Info_for_Reminder__c;
   }
 }
}

When a Campaign Member record is created/updated, this trigger populates a Rich Text field on the Campaign Member record (
Course_Email_Info_2__c) with the data contained within a Rich Text field that exists on the corresponding Campaign record (
Extra_Info_for_Reminder__c).

We're looking to move this trigger to Production, but I'm struggling to work out where to start when it comes to APEX Test Classes. I've looking for a comprehensive easy-to-follow tutorial, but can't find much.

Would anyone be able to suggest a simple APEX Test Class for this trigger?

Many thanks in advance,

Patrick

 
Shyama B SShyama B S
Hi,
Go through this link Apex Testing (https://developer.salesforce.com/trailhead/module/apex_testing). The tutorial is really good and hardly takes an hour. You will be able to write the test class yourself :) Please let me know if you need any help.
Thanks