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
BALA_RAMBALA_RAM 

Can please write test class for bulk trigger

trigger BulkCreating180upsell on Opportunity (after Update) 
{      
  List<Opportunity> o = new List<Opportunity>();
  //List<account> acc = new List<account>();
  
  Set<id>accId = new Set<Id>();
    //for(Account a :acc)
 // accId.add(aId);
    
  Set<Id> setId = new Set<Id>();
   for(Opportunity opp :trigger.new)
   {
   setId.add(opp.Id);
   accId.add(opp.accountId);
   }
  
            
      //opp.adderror(opp.AccountId);          
     // Account acc=[Select id,Name from Account where id=:opp.AccountId];        
      /*if(opp.StageName=='Closed Won' && opp.Name =='Up-Sell 90 days'+' ('+ mapacc.ContainsKey.Name +')')
      {                                   
        o.add(new Opportunity (Name ='Up-Sell 180 days'+' ('+ acc.Name +')',CloseDate=date.today().adddays(180),AccountId=mapacc.id,StageName='Prospecting'));         
      }*/
      Map<Id, Account> mapacc = new Map<Id, Account>([Select id,Name from Account where Id=:accId]);
      Map<Id, Opportunity> mapopp = new Map<Id, Opportunity>([Select id,Name,CloseDate,AccountId,StageName from Opportunity where Id=:setId]);
      
      for(Opportunity opp :trigger.new)
      {   
        /*opp.Name = mapopp.get(opp.Id).opp.'Up-Sell 180 days'+' ('+ mapacc.Name +')';
        opp.CloseDate=mapopp.get(opp.Id).opp.date.today().adddays(180);
        opp.AccountId=mapopp.get(opp.Id).opp.mapacc.Id;
        opp.StageName=mapopp.get(opp.Id).opp.'Prospecting';*/
        
        opportunity op=mapopp.get(opp.Id);
        Account ac=mapacc.get(opp.accountId);
         if(op.StageName=='Closed Won' && op.Name =='Up-Sell 90 days'+' ('+ ac.Name +')')
      {         
             /*Opportunity oppInsert = new Opportunity();
             oppInsert.Name = 'Up-Sell 180 days'+' ('+ aFullName +')';
             oppInsert.CloseDate = date.today().adddays(180);
             //oppInsert.AccountId = convertedLead.ConvertedAccountId;
             oppInsert.StageName = 'Prospecting';
             oppInsert.OwnerId=UserInfo[0].id;*/
                          
       o.add(new Opportunity (Name ='Up-Sell 180 days'+' ('+ ac.Name +')',CloseDate=date.today().adddays(180),AccountId=ac.id,StageName='Prospecting',LeadSource=opp.LeadSource));         
      }  
        
      }  
      //System.debug('Account Id is'+opp.AccountId);  
  insert o; 
}

HariDineshHariDinesh

Hi,

 

Find below test class to cover your trigger.

It is covering above 90%. Try to cover 100 if needed. Other wise use it as it is.

 

@isTest
public class testoppertunity
{


       public static testmethod void testoppertunityConstructor()
            {
            
               List<Account> listacc = new List<Account>();
               Account acc1 = new Account(Name = 'TestAccountName');
               Insert acc1;
              
               
               List<Opportunity> listOpportunity  = new list<Opportunity >();
                    
               Opportunity opp1 = new Opportunity (name = 'testoppname');
               opp1.accountid = acc1.id;
               opp1.StageName = 'Closed Won';
               opp1.CloseDate=Date.Today();
               insert opp1;
               opp1.StageName ='Closed Lost';
               update opp1;
                //Create a new instance of standard controller
                 
                
                Test.startTest();
                
                Test.stopTest();
            
            
            
            
            }

}

 

Find below link to get knowledge on writing test methods

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods