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
Chittineni SandeepChittineni Sandeep 

how to write a test class for this following trigger

for(Contracting_Status__c cs : trigger.New)
    {
        if(trigger.isInsert)
        contractingid.add(cs.id);
        if(cs.Account__c != null && (cs.Contracting_Status__c != null))
        contrct_Accntid.add(cs.Account__c);
        if(cs.Carrier__c != null && (cs.Contracting_Status__c != null))
        Carrier_id.add(cs.Carrier__c);
        if(cs.Agency__c != null && (cs.Contracting_Status__c != null))
        Contrct_Agencyid.add(cs.Agency__c);
        if(trigger.isUpdate && cs.Agreement_release_date__c <= system.today())
        Contract_Id.add(cs.id);
        system.debug(cs.Carrier__c+'****PRINT CARRIER NAME****');
        if(cs.Product_Type__c != null && cs.Carrier__c == '00180000010mfZlAAI')
        ProductCode = cs.Product_Type__c;    
    }

Thank you.
Best Answer chosen by Chittineni Sandeep
Prady01Prady01
Hi, The test class for a trigger would be just be to insert the test data on the object for which you have written trigger in the first place. Like the object you have used is Contracting_Status__c.

This data you insert would be in the test class.

Contracting_Status__c cs = new Contracting_Status__c();
insert cs;

just the above line in the test class would run your trigger. To cover each and every line you just have to take care of putting in the right data.

Hope it helps.
prady01

All Answers

Prady01Prady01
Hi, The test class for a trigger would be just be to insert the test data on the object for which you have written trigger in the first place. Like the object you have used is Contracting_Status__c.

This data you insert would be in the test class.

Contracting_Status__c cs = new Contracting_Status__c();
insert cs;

just the above line in the test class would run your trigger. To cover each and every line you just have to take care of putting in the right data.

Hope it helps.
prady01
This was selected as the best answer
Chittineni SandeepChittineni Sandeep
Thank you friend.