+ Start a Discussion
MikeCloudMikeCloud 

Trigger coverage problem - Create new Project record when Opp Custom field picklist value = Yes

Trigger: When a custom field picklist value in Opp = Yes, I want to create a new Project, make new Project name the same as the Opp name:

 

 

 

trigger CreateM1Project on Opportunity (after insert) {
    
    
   List<Milestone1_Project__c> NewProjects = new List<Milestone1_Project__c>();

    for (Opportunity opp: trigger.new)  {
        
 

 

 if (opp.Start_Project_Site_Id_Stage__c == 'Yes') {
        
            Milestone1_Project__c freshProject = new Milestone1_Project__c();
            freshProject.Name = opp.Name;
            
        }
    }
    insert NewProjects;
        
   }

nitinkhunal.ax1786nitinkhunal.ax1786

so you want to write a test class for this one?

Vinit_KumarVinit_Kumar

Try below code for Test Class :

 

@IsTest(SeeAllData=false)
public class CreateM1Project_test{

static testMethod void myTestMethod() {

Opportunity opp =new Opportunity(Name='Test',StageNAme='Prospecting',CloseDate=system.today(),Start_Project_Site_Id_Stage__c='Yes');

insert opp;


}
}

 

MikeCloudMikeCloud

Changed stage name which needs to be 'Closed Won' (set as field depencency), test failed am I missing something in the orignal code?

MikeCloudMikeCloud

I have no code coverage, test failed

Vinit_KumarVinit_Kumar

what is the error message you are getting while running the test ??

MikeCloudMikeCloud

I figured it out, I had anothe trigger running that needed to be edited, thanks for your reply.