You need to sign in to do that
Don't have an account?
Evan Maher 3
test class contact field copy to account field
So I'm new to writing apex triggers and need to push a few into production. My trigger code is:
trigger Days_Open on Contact (after insert,after update) { List<account> li=new list<Account>(); List<Id> ids = new List<Id>(); for(Contact c: trigger.new) ids.add(c.AccountId); Map<Id, Account> accountMap = new Map<Id, Account>([Select Id, Phone From Account Where Id In :ids]); for(Contact c: trigger.new) { Account a = accountMap.get(c.AccountId); if(a != null) { a.Days_Open__c = c.Days_Open__c; li.add(a); } } update li; }How do I write a test class? Trigger works in the environment. I need to have it check that when a contact record is saved it copies it to the account that the contact is related too. I currently cannot push into production as code coverage is at 0%
As per your logic you have to give valu to days_open__c fields also while inserting contact inorder to copy it to account.
try this code
Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.
Thanks and Regards
All Answers
As per your logic you have to give valu to days_open__c fields also while inserting contact inorder to copy it to account.
try this code
Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.
Thanks and Regards