You need to sign in to do that
Don't have an account?
Alex Meza
and this is my test class
Apex Trigger Code Deployment
I was able to write two apex triggers that connect two objects(Contacts and a Custom Object) via a lookup field when they have the same first name, last name, and zip code. This was done in my sandbox environment and I was able to get this working perfectly there. I then, with help through the moudles and references, was able to write a small sample test class in order to have this deployed in my production environment, but i am only able to get 24 percent coverage.
Please help as I am stuck, below is one of my triggers and my test class.
trigger VoterID2Contact on Voter_File_TX__c (before insert,before update,after insert,after update) { if(checkRecursive.runOnce){ return;} { Set<String> set_Str = new Set<string>(); Map<String,Contact> mp_ContactID; if(Trigger.isAfter && Trigger.isUpdate) { for(Contact ContactID : [Select ID,FirstName, LastName,MailingPostalCode, Voter_File_ID__c From Contact]) { if(mp_ContactID==null) mp_ContactID = new Map<String,Contact>(); mp_ContactID.put(ContactID.FirstName +''+ContactID.LastName +''+ContactID.MailingPostalCode,ContactID); } for(Voter_File_TX__c VoterList : Trigger.new) { if(mp_ContactID!=null && mp_ContactID.containsKey(VoterList.First_Name__c+''+ VoterList.Last_Name__c+''+ VoterList.Zipcode__c)) { mp_ContactID.get(VoterList.First_Name__c +''+ VoterList.Last_Name__c +''+ VoterList.Zipcode__c).Voter_File_ID__c = VoterList.id; } } if(mp_ContactID!=null && mp_ContactID.values()!=null) checkRecursive.runOnce = true; update mp_ContactID.values(); } } }
and this is my test class
@isTest public class TestClass { static testMethod void testMethod1() { Voter_File_TX__c vf = new Voter_File_TX__c(); vf.First_Name__c ='Test'; vf.Last_Name__c ='Test'; vf.RNC_ID__c = 'Test'; vf.Zipcode__c = 'Test'; insert vf; Contact cont = new Contact(); cont.FirstName ='Test'; cont.LastName = 'Test'; cont.RNC_ID__c = 'Test'; cont.MailingPostalCode = 'test'; insert cont; vf.First_Name__c = cont.FirstName ; vf.Last_Name__c = cont.LastName ; vf.Zipcode__c = cont.MailingPostalCode ; vf.RNC_ID__c = cont.RNC_ID__c ; vf.Contact__c = cont.Id ; cont.FirstName = vf.First_Name__c ; cont.LastName = vf.Last_Name__c ; cont.MailingPostalCode = vf.Zipcode__c; cont.RNC_ID__c = vf.RNC_ID__c ; } }
Let me know if this helps :)
Thanks!
Amit Singh
All Answers
Let me know if this helps :)
Thanks!
Amit Singh
Thanks!
Amit Singh
Thanks for you help now I just have to figure out how to change my code into an batch class.