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
anu.s1.3587621171560732E12anu.s1.3587621171560732E12 

Please help me out with this

Hi

 

Iam trying to write a test class for a trigger.am getting error.

 

trigger copyrecord on Opportunity (after update) 
{
 List<Opportunity> liopp = new List<Opportunity>();
 List<Won_opportunity__c> wonlist = new List<won_opportunity__c>();
 won_opportunity__c won;
 for(Opportunity opp :[select Name,StageName,Account.Name,Segment1__c,Sector__c,Courses__c,
     CloseDate,LeadSource,contact__r.Name,probability,people__c,Region1__c
      from Opportunity where Id IN : trigger.new])
      {
         if(opp.StageName == 'Closed Won')
             {
              won = new won_opportunity__c();
              won.Stage__c = opp.StageName;
              won.close_Date__c = opp.CloseDate;
              won.Name = opp.Name;
              won.Region__c = opp.Region1__c;
              won.segment__c = opp.segment1__c;
              won.Courses__c = opp.courses__c;
              won.Lead_source__c = opp.LeadSource;
              won.Probability__c = opp.Probability;
              won.people__c = opp.people__c;
              won.Account_Name__c = opp.Account.Name;
              won.Contact__c = opp.Contact__r.Name;             
              won.sector__c = opp.sector__c;      
              wonlist.add(won);
             }    
      }
     insert wonlist;
}

 Here is my test case

 

@istest(seealldata = false)
public class testcopyrecord_trigger {

public static testMethod void updrec(){

Account acc = new Account();
acc.Name = 'Test';
insert acc;

List<opportunity> opp = new List<opportunity>();

for(Integer i=0;i<5;i++){
opportunity o= new opportunity();
o.AccountId = acc.Id;
o.stage = 'Closed/Won';
opp.add(o);
}
insert opp;
opp[0].Stage=true;
update opp;
}
}

 So Am getting the following error

 

Error: Compile Error: Variable does not exist: Name at line 7 column 1

 

please help me 

 

venkateshyadav1243venkateshyadav1243

Hi anu

You are missing the reqired fields of opportunity thats y u r getting the error

 

add these fileds in u r for loop of opportunity

 

 

@istest(seealldata = false)
public class testcopyrecord_trigger {

public static testMethod void copyrecord(){

Account acc = new Account();
acc.Name = 'Test';
insert acc;

List<opportunity> opp = new List<opportunity>();

for(Integer i=0;i<5;i++){
opportunity o= new opportunity();
o.AccountId = acc.Id;
o.Name='test';
o.CloseDate=system.today();
o.StageName='Closed/Won';
opp.add(o);
}
insert opp;
//opp[0].Stage=true;
update opp;
}
}

 

 

try this .

 

 

Regards

venkatesh.