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
Sai ThejaSai Theja 

Can Someone help me to cover my code

Im new to salesforce
I need Test class for following Triggers to cover my code coverage

1.
trigger AccountCheckbox on Account (before update) {
if(trigger.isUpdate){
for(Account a : trigger.new){
if(a.Record_Updated__c == false){
a.Record_Updated__c = true;
}
}
}
}
--------------------------------------------------------------------------------------------
2.

trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) {
List<task> sai = New List<task>();

  for(opportunity opp:trigger.new){
   if(opp.stagename=='closed won'){
    task t=new task(whatid=opp.id);
    
    t.Subject = 'Opportunity Task';
    t.type= 'Call' ;
    t.ActivityDate = system.today();     
    
    sai.add(t); 
    }
   }
     insert sai;
}

---------------------------------------------------------------------------------------
3.


trigger DuplicateTask on Task (before insert, before update) {
for(task t : trigger.new){
list<task> tas = [select subject from task where subject = : t.subject];
if (tas.size()>0){
t.adderror('Task Name already exits');
}
}
}

 
Best Answer chosen by Sai Theja
UjwalaUjwala
Hi 
please fnd help from following code,

@istest
public class TestAccount {
   
    static testMethod void checkAccount()
    {
        account acc=new account(name='testAccountert');
        insert acc;
        acc.Record_Updated__c=false;
        update acc;
        
        opportunity opp=new opportunity(name='TestOpportunity', stagename='Closed Won',CloseDate=Date.parse('2/2/2019'));
        insert opp;
        
        
    }
    
    static testmethod void testTaskSubject(){
        DmlException expectedException;
        try{
        account acc=new account(name='testAccountert');
        insert acc;
       Task t = new Task();
        t.OwnerId = UserInfo.getUserId();
        t.Subject='TestTest';
        t.Status='Not Started';
        t.Priority='Normal';
        t.WhatID = acc.id;

        insert t; 
       Task t1 = new Task();
        t1.OwnerId = UserInfo.getUserId();
        t1.Subject='TestTest';
        t1.Status='Not Started';
        t1.Priority='Normal';
        t1.WhatID = acc.id;

        insert t1; 
        }
        catch (DmlException dmx)
            {
        expectedException = dmx;
            }
        system.assertNotEquals(null, expectedException, 'Task Name already exits');
    }
    
    }