You need to sign in to do that
Don't have an account?
Kunal Purohit 4
How to write test class for given trigger?
Hello All,
I have written below trigger. Now i want to write test class for same. Kindly provide your suggestion.
I have written below trigger. Now i want to write test class for same. Kindly provide your suggestion.
trigger ContactCount on Contact (after insert, after update, after delete, after undelete) { set<id> accid=new set<id>(); if(Trigger.isInsert|| Trigger.isUpdate|| Trigger.isUndelete){ for(Contact con:Trigger.new){ accid.add(con.AccountId); } } if(Trigger.isDelete|| Trigger.isUpdate){ for(Contact Con: Trigger.old){ accid.add(Con.AccountId); } } List<Account> aclist=[SELECT Id,Open_Contact_Count__c,(SELECT Id FROM Contacts WHERE Status__c= 'Open') FROM Account WHERE Id IN: accid]; for(Account acc: aclist){ acc.Open_Contact_Count__c= acc.Contacts.size(); } update aclist; }
You can try the below and modify it accordingly as it is a sample snippet.
Also, I would suggest you to check implementation on https://developer.salesforce.com/forums/?id=906F0000000AcdaIAC
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.