function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhinav_SFDCAbhinav_SFDC 

What else i have to do in my test class to get 75% Code coverage it's not working for my trigger???

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
trigger autoContact on Account (after insert) {
   
    List<contact> newContact = new List<contact>();
   
  
    for(Account acc: Trigger.new){
      
            Contact con = new Contact();
            con.FirstName = acc.Name;
            con.LastName = acc.Short_Name__c;
            con.Phone = acc.Phone;
            con.salutation = 'Mr.';
            con.AccountId = acc.id;
            newContact.add(con);
      }
           insert newContact;
     }
====================================================================

@isTest
Public Class autoContactTest{
    Static testmethod void MethodOne(){
        Account a = new Account();
        a.Name = 'ABVP';
        a.Phone = '0000000000';
        a.Short_Name__c = 'Abi';
       
        insert a;
       
        Contact c = new Contact();
        c.FirstName = 'ABVP';
        c.LastName = 'Abi';
        c.Phone = '0000000000';
        c.AccountId = '0019000000tgMdl';
        insert c;
          }
}

thanks in adv...:)
Anurag JainAnurag Jain
Hi,
you should avoid to writing hardcode id in your Test class as you write in you test class c.AccountId = '0019000000tgMdl';
instance of this you can use
c.AccountId = a.id;
else you class is looking fine... and it should be 100 % coverage.

Thanks
Anurag Jain