You need to sign in to do that
Don't have an account?
MS123456
pls use my trigger n write handler cls...
hi Nayana K...
trigger eventTriggerContact on Event (after insert, after update) { Set<Id> set_ContactId = new Set<Id>(); List<Contact> conList = new List<Contact>(); if(Trigger.isAfter && Trigger.isInsert) { for(Event e : Trigger.new) { if(e.whoId!=null && String.valueOf(e.whoId).startsWith('003') && (e.Type == 'Consult') ) { set_ContactId.add(e.whoId); } } Map<Id,Contact> conMap = new Map<Id,Contact>([Select Id,StartDateTime__c,Start_Time__c,User_Attorney_Profile_Page__c,User_First_Name__c, User_Last_Name__c,User_Office_Google_Map_Link__c,User_Office_Phone__c,Phone_Number_Text__c, User_Office_Website__c,One_of_Our_Attorneys__c,Most_Recent_Event_Id__c from contact where Id IN:set_ContactId]); for(Event e : Trigger.new) { if(conMap!=null && conMap.containsKey(e.whoId)) { conMap.get(e.whoId).StartDateTime__c= e.StartDateTime; conMap.get(e.whoId).Start_Time__c= e.Start_Time__c; conMap.get(e.whoId).User_Attorney_Profile_Page__c= e.User_Attorney_Profile_Page__c; conMap.get(e.whoId).User_First_Name__c= e.User_First_Name__c; conMap.get(e.whoId).User_Last_Name__c= e.User_Last_Name__c; conMap.get(e.whoId).User_Office_Google_Map_Link__c= e.User_Google_Map_Link__c; conMap.get(e.whoId).User_Office_Phone__c= e.User_Office_Phone__c; conMap.get(e.whoId).User_Office_Website__c = e.User_Office_Website__c ; conMap.get(e.whoId).Phone_Number_Text__c= e.Phone_Number_Text__c; conMap.get(e.whoId).Great_Hands_Text__c= e.Great_Hands_Text__c; conMap.get(e.whoId).One_of_Our_Attorneys__c= e.One_of_Our_Attorneys__c; conMap.get(e.whoId).Most_Recent_Event_Id__c=e.id; conList.add(conMap.values()); } } system.debug('!!!!!!'+ conList); if(conList!=null && conList.size()>0) update conList; } if(Trigger.isAfter && Trigger.isUpdate) { for(Event e : Trigger.new) { if(e.whoId!=null && String.valueOf(e.whoId).startsWith('003') && (e.Type == 'Consult')) { set_ContactId.add(e.whoId); } } Map<Id,Contact> conMap = new Map<Id,Contact>([Select Id,StartDateTime__c,Start_Time__c,User_Attorney_Profile_Page__c,User_First_Name__c, User_Last_Name__c,User_Office_Google_Map_Link__c,User_Office_Phone__c,Phone_Number_Text__c, User_Office_Website__c,One_of_Our_Attorneys__c,Most_Recent_Event_Id__c from contact where Id IN:set_ContactId]); for(Event e : Trigger.new) { if(conMap!=null && conMap.containsKey(e.whoId) && e.id == conMap.get(e.whoId).Most_Recent_Event_Id__c) { conMap.get(e.whoId).StartDateTime__c= e.StartDateTime; conMap.get(e.whoId).Start_Time__c= e.Start_Time__c; conMap.get(e.whoId).User_Attorney_Profile_Page__c= e.User_Attorney_Profile_Page__c; conMap.get(e.whoId).User_First_Name__c= e.User_First_Name__c; conMap.get(e.whoId).User_Last_Name__c= e.User_Last_Name__c; conMap.get(e.whoId).User_Office_Google_Map_Link__c= e.User_Google_Map_Link__c; conMap.get(e.whoId).User_Office_Phone__c= e.User_Office_Phone__c; conMap.get(e.whoId).User_Office_Website__c = e.User_Office_Website__c ; conMap.get(e.whoId).Phone_Number_Text__c= e.Phone_Number_Text__c; conMap.get(e.whoId).Great_Hands_Text__c= e.Great_Hands_Text__c; conMap.get(e.whoId).One_of_Our_Attorneys__c= e.One_of_Our_Attorneys__c; conList.add(conMap.values()); } } system.debug('!!!!!!'+ conList); if(conList!=null && conList.size()>0) update conList; } }
Handler class like below
Trigger
Trigger Best Practices | Sample Trigger Example | Implementing Trigger Framework
http://amitsalesforce.blogspot.com/2015/06/trigger-best-practices-sample-trigger.html
Let us know if this will help you
All Answers
I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
You write a test class for this the same way that you would any other:
- Set up some data for the Trigger to access (Like Contact and Event)
- Instantiate the Trigger- by insert event and update event
- Execute a method/methods
- Verify the behaviour with asserts.
Please try below test class
Let us know if this will help you
Handler class like below
Trigger
Trigger Best Practices | Sample Trigger Example | Implementing Trigger Framework
http://amitsalesforce.blogspot.com/2015/06/trigger-best-practices-sample-trigger.html
Let us know if this will help you