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
RahulRahul 

Hello Friends, can you help me cover this code. I have 45% code coverage. Thanks

public class QuoteHandler_PayTerms_GenerateDoc {

            Public void Documenttemplate(list<SBQQ__Quote__c> newlist) {
            
            list<SBQQ__QuoteTemplate__c> qt = [select id,Name,SBQQ__Default__c  from SBQQ__QuoteTemplate__c];
            Map<String, SBQQ__QuoteTemplate__c> quoteMap1 = new Map<String, SBQQ__QuoteTemplate__c>();
             for(SBQQ__QuoteTemplate__c q :qt) {
              quoteMap1.put(q.Name, q);
             }
            SBQQ__QuoteTemplate__c qt0 = quoteMap1.get('Auto Renew');
            Map<string, SBQQ__QuoteTemplate__c> quoteMap = new Map<String, SBQQ__QuoteTemplate__c>();
            
                 for(SBQQ__Quote__c ss : newlist) 
                 {
                 
                        if(qt0 != null) {
                            qt0.SBQQ__Default__c = false;
                            quoteMap.put('qt0',qt0);
                        }
                }
                if(ss.Document_Template__c=='Auto Renew' && ( ss.SBQQ__PaymentTerms__c=='Monthly' ||  ss.SBQQ__PaymentTerms__c=='Quarterly') && ss.SBQQ__TotalCustomerDiscountAmount__c > 0 && ss.Long_Form__c==False && ss.Logo__c == True) 
                  {
                      if(qt0 != null)
                      qt0.SBQQ__Default__c = true;
                      qt0.SBQQ__LogoDocumentId__c = '015540000001owj';
                      quoteMap.put('qt0',qt0);
                  }                
                
                                     try{
                            update quoteMap.values();            
                        }
                        catch(exception e) {
                            system.debug('error:'+e);
                        }
        
            }

}

test class:-
@isTest(seeAllData = true)
public class QuoteTrigger_PayTerms_GenerateDoc_Test{
         Static testMethod Void testMethod2(){
           Test.starttest();
            Account acc = new Account();
             acc.Name = 'Test Account';
             acc.Website ='www.test.com';
             acc.Type='Banking';
             insert acc;
             
             opportunity opp = new opportunity();
             opp.name ='Test Opp';
             opp.stagename='Closed Won';
             opp.Type= 'New Business';
             opp.CloseDate=system.today().addmonths(2);
             opp.Upsell_Potential__c ='No';
             opp.RenewalDate__c = system.today();
             opp.accountid=acc.id;
             insert opp;  
             
            
             SBQQ__Quote__c oldquote = new SBQQ__Quote__c();
             oldquote.SBQQ__Primary__c = true;
             oldquote.SBQQ__Opportunity2__c = opp.id;          
             oldquote.SBQQ__StartDate__c = system.today();
             oldquote.SBQQ__EndDate__c= system.today().addmonths(3);
             oldquote.SBQQ__SubscriptionTerm__c=1;
             oldquote.Status_Of_Approval__c='Pending';
             oldquote.Document_Template__c= 'Auto Renew';
             oldquote.SBQQ__PaymentTerms__c= 'monthly';
             oldquote.SBQQ__BillingCountry__c ='United States';
             oldquote.Long_Form__c = false;
             oldquote.Logo__c = true;
             
             insert oldquote;
             SBQQ__QuoteTemplate__c qt0 = new SBQQ__QuoteTemplate__c();

               qt0.Name='Auto renew';
               qt0.SBQQ__Default__c=false;
               qt0.SBQQ__PageWidth__c= 8.5;
               qt0.SBQQ__TopMargin__c =0.50;
               qt0.SBQQ__LeftMargin__c = 0.50;
               qt0.SBQQ__PageHeight__c  =11.00;
               qt0.SBQQ__BottomMargin__c = 0.50;   
               qt0.SBQQ__RightMargin__c = 0.50;
               qt0.SBQQ__FontFamily__c = 'Helvetica';
               qt0.SBQQ__ShadingColor__c = 'FFFFFF';   
               qt0.SBQQ__BorderColor__c = '000000';
               qt0.SBQQ__FontSize__c = 9.0;
               qt0.SBQQ__LogoDocumentId__c = '015540000001owj';
               insert qt0;

}
 
paul diracpaul dirac
Hi Rahul,
First of all please remove the annotation : (seeAlldata = true) this is not a best practice(because in that case your test class depend on  your sandbox data), especially for your needing, the annotation is just useless, since you replicate data with your QuoteTrigger_PayTerms_GenerateDoc_Test method. If you need some other data just createanother method that insert it. Consider also to split the creation of each object inide an appropriate method, e.g. one method that generates account, one for quote ecc.
After that, create a method that call the apex class you want to test, then just verify (with a query on data you inserted in test methods) and assert that data after processing are correct base on the value you expect, this also helps to identify issues in your code.
See apex testing module on trailhead for tips & bp:

https://trailhead.salesforce.com/en/content/learn/modules/apex_testing