+ Start a Discussion
Sudhir_MeruSudhir_Meru 

Code Coverage 67% to 75%

Hi, 

 

  I am new to salesforce wanted to know how to make code coverage to 75% from 67%. Below is the class i am using to check the code coverage. I need to deploy this to production.  Please suggest me how to modify the below class and make to get 75% Please suggest me 

 

public class DRConvertToOpportunitycontroller {

    public DRConvertToOpportunitycontroller (ApexPages.StandardController controller) {
    }
   
    Opportunity opp = new opportunity();

    public PageReference save() {
        string str = apexpages.currentpage().getparameters().get('id');
        System.debug('str == '+str);

        DealReg__c deal = [SELECT id, customer_name__c, deal_stage__c,
                            account_id__c, estimated_close_date__c,
                            estimated_value__c, competitor__c,
                            account__c, project_name__c,
                            distributor__c, reseller__c,
                            channel_source__c, discount_program__c,
                            ownerid, status__c, owner.type,
                            field_representative__c, theater__c,
                            Partner_Initiated__c,Partner_Led__c,K_12__c 
                        FROM DealReg__c
                        WHERE id = :str];
                        
      // Coded by Sudhir to Get User Information and Region Information from User Object                      
      // String userName = UserInfo.getUserName();                          
   // User Urs = [SELECT Region__c FROM User WHERE Username = : userName limit 1];                      
                          
        opp.name = Deal.project_name__c +  ' ' +'FOR'+' '+deal.customer_name__c;
        // Deal Field Representative field value will be used as Opportunity Owner, when available.
        // Else, Deal Owner field will be used.
        
        if (Deal.field_representative__c <> null) 
         {
           opp.OwnerId = Deal.field_representative__c;
        } else {
           opp.OwnerId = Deal.OwnerId;
        }
        
        // For NAM, Deal Owner (ISR) will become the Opportunity Secondary Owner
        if (Deal.theater__c == 'NAM') {
           opp.Secondary_Owner__c = Deal.OwnerId;    
           if ( opp.Partner_Driven__c == 'Yes'  && opp.Partner_Led__c == 'No' && opp.K_12__c == 'No'  ) 
           {
           opp.discount_program__c = 'DEALREG/PI';
           opp.Abbv_Discount_Program__c = 'DR/PI';        
           }
         else if ( opp.Partner_Driven__c == 'No'  && opp.Partner_Led__c == 'Yes' && opp.K_12__c == 'No'  ) 
         {
          opp.discount_program__c = 'DEALREG/PL';
          opp.Abbv_Discount_Program__c = 'DR/PL';    
         }
         else if ( opp.Partner_Driven__c == 'Yes'  && opp.Partner_Led__c == 'Yes' && opp.K_12__c == 'No'  ) 
         {
          opp.discount_program__c = 'DEALREG/PI/PL';
          opp.Abbv_Discount_Program__c = 'DR/PI/PL';  
         }
        else if ( opp.Partner_Driven__c == 'No'  && opp.Partner_Led__c == 'No' && opp.K_12__c == 'Yes' ) 
        {
         opp.discount_program__c = 'DEALREG/K-12';
         opp.Abbv_Discount_Program__c = 'DR/K12';    
        }
        else if ( opp.Partner_Driven__c == 'Yes'  && opp.Partner_Led__c == 'No' && opp.K_12__c == 'Yes' )
        {
        opp.discount_program__c = 'DEALREG/PI/K-12';
        opp.Abbv_Discount_Program__c = 'DR/PI/K12';    
        }
        else if (   opp.Partner_Driven__c == 'No'  && opp.Partner_Led__c == 'Yes' && opp.K_12__c == 'Yes'  )
        {
        opp.discount_program__c = 'DEALREG/PL/K-12';
        opp.Abbv_Discount_Program__c = 'DR/PL/K12';   
        }
        else if ( opp.Partner_Driven__c == 'Yes'  && opp.Partner_Led__c == 'Yes' && opp.K_12__c == 'Yes' )
        {
        opp.discount_program__c = 'DEALREG/PI/PL/K-12';
        opp.Abbv_Discount_Program__c = 'DR/PI/PL/K12';   
        }
       else
       {
        opp.discount_program__c = 'DEALREG';
        opp.Abbv_Discount_Program__c = 'DR';     
        }   
       }
       else
      {
       opp.discount_program__c = 'NSP';
       opp.Abbv_Discount_Program__c = 'NSP';   
      } 
           
              
        opp.StageName = Deal.deal_stage__c;
        opp.CloseDate = Deal.estimated_close_date__c;
        opp.Primary_Competitor__c = deal.competitor__c;
        opp.type = 'Existing Customer';
        opp.Government_Contract__c = 'None';
        opp.leadsource = 'Deal Registration';
        opp.Partner_Driven__c = 'yes';
        opp.Partner_Account__c = deal.reseller__c;
        opp.primary_distributor__c = deal.distributor__c;
        opp.primary_reseller__c = deal.reseller__c;
        opp.channel_source__c = deal.channel_source__c;
        opp.K_12__c  = deal.K_12__c;
        opp.Renewal_Opportunity__c = 'No';
        opp.Renewal_Incumbant_Reseller__c = 'No';
        opp.Renewal_K_12__c = 'No';    
        opp.DEALREG_SEND_QUOTE__c = 'Do Not Send';
        opp.RENEWAL_SEND_QUOTE__c = 'Do Not Send';  
        opp.accountid = deal.account__c;        
        opp.deal_registration__c = deal.id; 
        
        // mapping deal columns with oppertunity columns
        opp.Partner_Driven__c = deal.Partner_Initiated__c;
        opp.Partner_Led__c = deal.Partner_Led__c;      
      
      if(deal.Status__c <> 'Approved'){
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Only an approved Deal can be converted to an Opportunity.'));
           return null;
        } else if(deal.owner.type == 'Queue'){
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'A Deal needs to be assigned before it can be converted to an Opportunity.'));
           return null;
        } else{
     
         insert opp;
     
            PageReference pg = new PageReference('/'+opp.id);
            return pg;
        }
    } 
}

 

wixxeywixxey

You should study the blog in the given link. It will help you how to write a test case for you controller extension.

 

http://salesforcesource.blogspot.com/2008/09/testing-your-controller-extentions.html