I recently wrote my very first trigger and I'm looking to deploy to production. Before deploying I need help with writing test code but I don't know what I'm doing. Basically i want to test my trigger but I don't know how to write test cold. the goal is to enter a date in the opportunity object field titled: Initial Field Visit Completed. I have copied the trigger below and if you guys can provide suggestions that would be greatly appreciated.
trigger FieldVisitCompleted on Opportunity (after insert,after update) {
Set <Id> oppIds = new Set<Id>();
List<Lead_Source__c> ls= new List<Lead_Source__c>();
for (Opportunity parentObj : Trigger.new)
{
oppIds.add(parentObj.Id);
}
Map<Id, Lead_Source__c> parentObjList = new Map<Id, Lead_Source__c>([Select Id,Effort__c,Initial_Field_Visit__c FROM Lead_Source__c WHERE Effort__c IN :oppIds]);
for (Lead_Source__c lsrc : parentObjList.values()) {
System.debug('lead source'+lsrc);
Opportunity opp = Trigger.newMap.get(lsrc.Effort__c);
Opportunity o = Trigger.oldMap.get(lsrc.Effort__c);
System.debug('opp field'+opp.Initial_Field_Visit_Completed__c);
System.debug('opp field'+ o.Initial_Field_Visit_Completed__c);
if(opp.Initial_Field_Visit_Completed__c != o.Initial_Field_Visit_Completed__c){
lsrc.Initial_Field_Visit__c = opp.Initial_Field_Visit_Completed__c;
System.debug('lsrc field'+lsrc.Initial_Field_Visit__c);
ls.add(lsrc);
}
}
if(!ls.isEmpty()){
update ls;
}
}
Here is what I have so far for test code
@isTest
public class FieldVisitTestClass {
static testMethod void myTest() {
Opportunity opp = new Opportunity();
opp.name = 'Michael Jordan';
opp.AccountId = opp.Id;
}
}
Looking for some direction as to where to go from here.