• sapnasolanki
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

My apex class is as below -

 

public class QuoteController
{
    
    Account account {get;set;}
    Opportunity opportunity{get;set;}
    Quote__c quote;
    Design_Rev__c dr;
    public Boolean designRevFlag {get; set;}
    public Boolean psiDesignFlag {get; set;}
     String accId {get;set;}
     String accName {get;set;}
 

    
    
    public Account getAccount()
       {
        if(account == null) account = new Account();
          return account;
    }
       public Opportunity getOpportunity()
       {
        if(opportunity == null) opportunity = new Opportunity();
          return opportunity;
       }
       public Quote__c getQuote()
    {
        if(quote == null) quote = new Quote__c();
          return quote;
    }
     public Design_Rev__c getDesign_Rev()
    {
        if(dr == null) dr = new Design_Rev__c ();
          return dr;
    }

    public QuoteController()
    {
        opportunity = new Opportunity();
        account = new Account();
        quote = new quote__c();
        dr = new Design_Rev__c();
        
        //setting initial default values
        opportunity.Name = ApexPages.currentPage().getParameters().get('name');
        If(opportunity.Name == '')
            opportunity.Name = account.Name;
        //account.id = Apexpages.currentPage().getParameters().get('accId');
        opportunity.StageName = 'New Prospect';
        dr.Rev__c = 'A';
        dr.System__c = 'PW - Playworld Independent';
        dr.Units__c = 'Imperial';
        dr.Post__c = 'Steel-Footed';
        dr.Age_Group__c = 'ASTM 5-12';
        dr.Compliance_Criteria__c = 'ASTM-F1487-07';
        dr.Specifications__c = 'N/A';
        dr.Shade_MPH__c = '150';
        dr.Border_Timbers__c = 'N/A';
        dr.Certified_Drawings__c = 'N/A';
        dr.X2D_CAD_File__c = 'N/A';
        
       
        
        
    }
   
   
   public PageReference step1()
   {
        String aName = account.Name;
        System.debug('aName'+aName);
          return Page.opptyStep1;
   }

   public PageReference step2()
   {
      return Page.opptyStep2;
   }

   public PageReference step3()
   {
      return Page.opptyStep3;
   }


   
   
   //to copy billing info to shipping info
    public PageReference copyShippingInfo()
       {
           account.ShippingStreet = account.BillingStreet;
           account.ShippingCity = account.BillingCity;
           account.ShippingState = account.BillingState;
           account.ShippingCountry = account.BillingCountry;
           account.ShippingPostalCode = account.BillingPostalCode;
           account.ShippingCountry = account.BillingCountry;
        return Page.opptyStep1;
    }
    
    // This method cancels the wizard, and returns the user to the accounts tab
    
 
    public PageReference cancel()
    {
            PageReference opportunityPage = new Pagereference('/001/o');
            opportunityPage.setRedirect(true);
            return opportunityPage;
    }

   
    Public PageReference saveaccount()
       {
        return Page.opptyStep2;
    }
   
    Public PageReference saveOppty()
    {
    //    accId = ApexPages.currentPage().getParameters().get('accId');
//        System.debug('ID::'+accId);
        
        return Page.opptyStep3;
    }
   
    Public PageReference saveQuote()
    {
            if(quote.Designer__c == 'Playworld Designer')
            {
                
                return Page.opptyStep4;
            }
            /*if(quote.Designer__c == 'Playworld Designer')
            {
                designRevFlag = False;
                psiDesignFlag = True;
            }*/
            else
            {
                
                return Page.opptyStep5;
            }
    }
    
    Public PageReference saveDesignRev()
    {
        accId = ApexPages.currentPage().getParameters().get('accId');
        System.debug('ID in save design rev:'+accId);
        If(accId == NULL)
        {
            insert account;
            opportunity.accountId = account.id;
            opportunity.Name = account.Name;
        }
        else
        {
            Account a = [Select Id,Name from Account where Id = :accId];
            //System.debug('in else'+a[0]);
            
            /*Account a = new Account();
            try
            {
                a = [SELECT Id,Name from Account where Id = :accId];
            }
            catch(System.QueryException e)
            {
                System.debug('in catch'+e);
            
                
            }    */
            System.debug('in else'+a);
            opportunity.AccountId = accId;
            opportunity.Name = a.Name;
            //opportunity.AccountId = a.Id;
        }
        system.debug('outside of if and else');
        //opportunity.Name = name;
           insert opportunity;
       //    opportunity.AccountId = accId;
   //        update opportunity;
           
           system.debug(' oppty inserted'+opportunity.Id);
           quote.Project__c = opportunity.Id;
           insert quote;
           system.debug('quote inserted'+quote.Id);
           
           dr.Quote__c = quote.Id;
           dr.Project__c = opportunity.id;
           insert dr;
           system.debug('dr inserted'+dr.id);
           
        PageReference accountPage = new Pagereference('/001/o');
        accountPage.setRedirect(true);
        return accountPage;
        
    //    String ObjectPrefix = Account.sObjectType.getDescribe().getKeyPrefix();
              
      //  PageReference p = new PageReference('/'+ObjectPrefix);
      //  p.setRedirect(true);
 
               
        //return p;  
        
    }
    
   public PageReference save()
   {
      insert account;

    
      opportunity.accountId = account.id;
      insert opportunity;


      PageReference opptyPage = new ApexPages.StandardController(opportunity).view();
      opptyPage.setRedirect(true);

      return opptyPage;
   }

}

 

And the test class is -

public class testQuoteController
{

   static testMethod void testing()
   {
           QuoteController qc = new QuoteController();
           qc.getAccount();
           qc.getDesign_Rev();
           qc.getOpportunity();
           qc.getQuote();
           //If(opportunity.Name == '')
           // opportunity.Name = 'test';
            
        qc.step1();
           qc.step2();
           qc.step3();
   
           Account a = new Account();
           a.BillingStreet = '123 main street';
           a.BillingCity = 'Test';
           a.BillingState = 'PA';
           a.BillingPostalCode = '12345';
           a.BillingCountry = 'USA';
   
       
           qc.copyShippingInfo();
           
           System.assertEquals(a.BillingStreet, '123 main street');
           qc.cancel();
           qc.saveaccount();
   //qc.saveDesignRev();
           qc.saveOppty();
         
        
        //qc.save();
        
       Quote__c q = new Quote__c();
       q.Designer__c = 'Agency';
       qc.saveQuote();
      // Account a1 = [select id,name from account where name like '%test%'];
      Account account = new Account();
       Opportunity o = new Opportunity();
       o.Name = 'test';
       o.CloseDate = Date.newInstance(2012,12,31);
       o.AccountId = a.id;
       o.StageName = 'New Prospect';
       o.Type = 'Direct Agency';
       account.BillingStreet = '123 main street';
           account.BillingCity = 'Test';
           account.BillingState = 'PA';
           account.BillingPostalCode = '12345';
           account.BillingCountry = 'USA';
           account.Name = 'test';
           
           
   }
   
   
}

How can i increase the code coverage. Right now it is 67%

This my Trigger code. What should the test class be for this for coverage?

 

trigger closedWonOppt on Opportunity (after Update)
{
    Opportunity opp = trigger.new[0];
    String oppId = opp.id;
    System.debug('oppId'+oppId);
    System.debug('in trigger');
    if(opp.StageName == 'Closed Won')
    {
        System.debug('in if');
        ACL__c acl = new ACL__c();
        Datetime today = datetime.now();
        Integer year = today.year();
        
        Opportunity opp1=[SELECT Name, Account.Name,Account.Id, RecordType.Name FROM Opportunity 
        where id = :oppId];
         
        acl.Name = opp1.Account.Name + ' - ' + opp1.RecordType.Name + ' - ' + String.valueOf(year);
        acl.Opportunity__c = opp1.Id;
        acl.account__C = opp1.Account.Id;
        // acl.Opportunity__c = opp1.Id;
         
        insert acl;
    }
}

My apex class is as below -

 

public class QuoteController
{
    
    Account account {get;set;}
    Opportunity opportunity{get;set;}
    Quote__c quote;
    Design_Rev__c dr;
    public Boolean designRevFlag {get; set;}
    public Boolean psiDesignFlag {get; set;}
     String accId {get;set;}
     String accName {get;set;}
 

    
    
    public Account getAccount()
       {
        if(account == null) account = new Account();
          return account;
    }
       public Opportunity getOpportunity()
       {
        if(opportunity == null) opportunity = new Opportunity();
          return opportunity;
       }
       public Quote__c getQuote()
    {
        if(quote == null) quote = new Quote__c();
          return quote;
    }
     public Design_Rev__c getDesign_Rev()
    {
        if(dr == null) dr = new Design_Rev__c ();
          return dr;
    }

    public QuoteController()
    {
        opportunity = new Opportunity();
        account = new Account();
        quote = new quote__c();
        dr = new Design_Rev__c();
        
        //setting initial default values
        opportunity.Name = ApexPages.currentPage().getParameters().get('name');
        If(opportunity.Name == '')
            opportunity.Name = account.Name;
        //account.id = Apexpages.currentPage().getParameters().get('accId');
        opportunity.StageName = 'New Prospect';
        dr.Rev__c = 'A';
        dr.System__c = 'PW - Playworld Independent';
        dr.Units__c = 'Imperial';
        dr.Post__c = 'Steel-Footed';
        dr.Age_Group__c = 'ASTM 5-12';
        dr.Compliance_Criteria__c = 'ASTM-F1487-07';
        dr.Specifications__c = 'N/A';
        dr.Shade_MPH__c = '150';
        dr.Border_Timbers__c = 'N/A';
        dr.Certified_Drawings__c = 'N/A';
        dr.X2D_CAD_File__c = 'N/A';
        
       
        
        
    }
   
   
   public PageReference step1()
   {
        String aName = account.Name;
        System.debug('aName'+aName);
          return Page.opptyStep1;
   }

   public PageReference step2()
   {
      return Page.opptyStep2;
   }

   public PageReference step3()
   {
      return Page.opptyStep3;
   }


   
   
   //to copy billing info to shipping info
    public PageReference copyShippingInfo()
       {
           account.ShippingStreet = account.BillingStreet;
           account.ShippingCity = account.BillingCity;
           account.ShippingState = account.BillingState;
           account.ShippingCountry = account.BillingCountry;
           account.ShippingPostalCode = account.BillingPostalCode;
           account.ShippingCountry = account.BillingCountry;
        return Page.opptyStep1;
    }
    
    // This method cancels the wizard, and returns the user to the accounts tab
    
 
    public PageReference cancel()
    {
            PageReference opportunityPage = new Pagereference('/001/o');
            opportunityPage.setRedirect(true);
            return opportunityPage;
    }

   
    Public PageReference saveaccount()
       {
        return Page.opptyStep2;
    }
   
    Public PageReference saveOppty()
    {
    //    accId = ApexPages.currentPage().getParameters().get('accId');
//        System.debug('ID::'+accId);
        
        return Page.opptyStep3;
    }
   
    Public PageReference saveQuote()
    {
            if(quote.Designer__c == 'Playworld Designer')
            {
                
                return Page.opptyStep4;
            }
            /*if(quote.Designer__c == 'Playworld Designer')
            {
                designRevFlag = False;
                psiDesignFlag = True;
            }*/
            else
            {
                
                return Page.opptyStep5;
            }
    }
    
    Public PageReference saveDesignRev()
    {
        accId = ApexPages.currentPage().getParameters().get('accId');
        System.debug('ID in save design rev:'+accId);
        If(accId == NULL)
        {
            insert account;
            opportunity.accountId = account.id;
            opportunity.Name = account.Name;
        }
        else
        {
            Account a = [Select Id,Name from Account where Id = :accId];
            //System.debug('in else'+a[0]);
            
            /*Account a = new Account();
            try
            {
                a = [SELECT Id,Name from Account where Id = :accId];
            }
            catch(System.QueryException e)
            {
                System.debug('in catch'+e);
            
                
            }    */
            System.debug('in else'+a);
            opportunity.AccountId = accId;
            opportunity.Name = a.Name;
            //opportunity.AccountId = a.Id;
        }
        system.debug('outside of if and else');
        //opportunity.Name = name;
           insert opportunity;
       //    opportunity.AccountId = accId;
   //        update opportunity;
           
           system.debug(' oppty inserted'+opportunity.Id);
           quote.Project__c = opportunity.Id;
           insert quote;
           system.debug('quote inserted'+quote.Id);
           
           dr.Quote__c = quote.Id;
           dr.Project__c = opportunity.id;
           insert dr;
           system.debug('dr inserted'+dr.id);
           
        PageReference accountPage = new Pagereference('/001/o');
        accountPage.setRedirect(true);
        return accountPage;
        
    //    String ObjectPrefix = Account.sObjectType.getDescribe().getKeyPrefix();
              
      //  PageReference p = new PageReference('/'+ObjectPrefix);
      //  p.setRedirect(true);
 
               
        //return p;  
        
    }
    
   public PageReference save()
   {
      insert account;

    
      opportunity.accountId = account.id;
      insert opportunity;


      PageReference opptyPage = new ApexPages.StandardController(opportunity).view();
      opptyPage.setRedirect(true);

      return opptyPage;
   }

}

 

And the test class is -

public class testQuoteController
{

   static testMethod void testing()
   {
           QuoteController qc = new QuoteController();
           qc.getAccount();
           qc.getDesign_Rev();
           qc.getOpportunity();
           qc.getQuote();
           //If(opportunity.Name == '')
           // opportunity.Name = 'test';
            
        qc.step1();
           qc.step2();
           qc.step3();
   
           Account a = new Account();
           a.BillingStreet = '123 main street';
           a.BillingCity = 'Test';
           a.BillingState = 'PA';
           a.BillingPostalCode = '12345';
           a.BillingCountry = 'USA';
   
       
           qc.copyShippingInfo();
           
           System.assertEquals(a.BillingStreet, '123 main street');
           qc.cancel();
           qc.saveaccount();
   //qc.saveDesignRev();
           qc.saveOppty();
         
        
        //qc.save();
        
       Quote__c q = new Quote__c();
       q.Designer__c = 'Agency';
       qc.saveQuote();
      // Account a1 = [select id,name from account where name like '%test%'];
      Account account = new Account();
       Opportunity o = new Opportunity();
       o.Name = 'test';
       o.CloseDate = Date.newInstance(2012,12,31);
       o.AccountId = a.id;
       o.StageName = 'New Prospect';
       o.Type = 'Direct Agency';
       account.BillingStreet = '123 main street';
           account.BillingCity = 'Test';
           account.BillingState = 'PA';
           account.BillingPostalCode = '12345';
           account.BillingCountry = 'USA';
           account.Name = 'test';
           
           
   }
   
   
}

How can i increase the code coverage. Right now it is 67%

This my Trigger code. What should the test class be for this for coverage?

 

trigger closedWonOppt on Opportunity (after Update)
{
    Opportunity opp = trigger.new[0];
    String oppId = opp.id;
    System.debug('oppId'+oppId);
    System.debug('in trigger');
    if(opp.StageName == 'Closed Won')
    {
        System.debug('in if');
        ACL__c acl = new ACL__c();
        Datetime today = datetime.now();
        Integer year = today.year();
        
        Opportunity opp1=[SELECT Name, Account.Name,Account.Id, RecordType.Name FROM Opportunity 
        where id = :oppId];
         
        acl.Name = opp1.Account.Name + ' - ' + opp1.RecordType.Name + ' - ' + String.valueOf(year);
        acl.Opportunity__c = opp1.Id;
        acl.account__C = opp1.Account.Id;
        // acl.Opportunity__c = opp1.Id;
         
        insert acl;
    }
}