+ Start a Discussion
Chris - ARIChris - ARI 

Test Class for Insert New Opportunity

Test Class keeps failing. What is wrong here?
 
@isTest
public class Test_OppWonChatter {
    static testMethod void insertNewOpportunity(){
        
        Account a = new Account(Name = 'Test');
        
        insert a;
        
        
        Opportunity o = new Opportunity();
        o.name = 'Test';
        o.AccountId = a.Id;
        o.StageName = 'Closed Won';
        o.CloseDate = date.today();
        o.Type = 'New Customers';
        
        insert o;
    }
}

 
Rakesh51Rakesh51
Looks good to me. What was the error ?
Chris - ARIChris - ARI
User-added image
Rakesh51Rakesh51
click on view and check the error reason 
Chris - ARIChris - ARI
Looks like that was initially caused by a validation error so I added a couple more fields but am still failing the test.
 
@isTest
public class Test_OppWonChatter {
    static testMethod void insertNewOpportunity(){
        
        Account a = new Account();
        a.Name = 'Test';
        a.Fleet_Size__c = 100;
        a.Industry = 'Retail';
        
        insert a;
        
        
        Opportunity o = new Opportunity();
        o.name = 'Test';
        o.AccountId = a.Id;
        o.StageName = 'Closed Won';
        o.CloseDate = date.today();
        o.Type = 'New Customers';
        
        insert o;
    }
}

User-added image