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
Anant Pandey 8Anant Pandey 8 

@isTest for Contact Trigger

Please suggest me Test Class for below Trigger
 
trigger ContactToOpportunity on Contact (After insert) {

   List <Opportunity>  Opps = new list<Opportunity>();
    
    for (Contact c: trigger.new ){
        Opportunity o = new Opportunity (Name = c.FirstName,  
        CloseDate = system.today().addmonths(1),
        StageName = 'Prospecting'      
        );
     Opps.add(o);
        
            }
   
    Insert Opps;
        
}

 
SATHISH REDDY.SATHISH REDDY.
Here you go.
@isTest
public class contactToOpportunityTest{
    static testmethod void afterInsertTestMethod(){
        Contact c = new Contact(FirstName = 'TestFN', LastName = 'TestLN', email = 'test@mail.com');
        insert c;
    }
}

Please mark as the best answer if it helps. Thanks!
SATHISH REDDY.SATHISH REDDY.
@Anant - Please mark as the best answer if it helps. Thanks!