• Evan Maher 3
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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%
 
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%