• jakin prajapati
  • NEWBIE
  • 25 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi ,

I have created a custom VF page to dipsplay list of quotes based on the quote status which is working but the Code coverage on test class is just 68%. 
VF Code
<apex:page StandardController="Quote" extensions="QuotePgeCtrl" sidebar="true" tabStyle="HPQuotes__tab">
    <html>
    <div class="blank">&nbsp;</div>
    <div class="content"><img src="/s.gif" class="pageTitleIcon" title="Quote"/>
    <h1>Quotes</h1><br>
    <font size="5">Home</font></br>
    <div class="blank">&nbsp;</div>
    </div></html>
     
    <apex:form >
        <apex:pageBlock title="Recent Quotes">
                <b>View:  </b>
                <apex:selectList size="1" value="{!quotevalue}">
                <apex:actionSupport event="onchange" action="{!getreviewdqt}" rerender="table1"/>
                <apex:selectOption itemLabel="None" itemValue="None"></apex:selectOption>
                <apex:selectOption itemLabel="Draft Quotes" itemValue="Draft Quotes"></apex:selectOption>
                <apex:selectOption itemLabel="Accepted Quotes" itemValue="Accepted Quotes"></apex:selectOption>
                <apex:selectOption itemLabel="Review Pending Quotes" itemValue="Review Pending Quotes"></apex:selectOption>
                </apex:selectList>
                
               <div style="width:100%; margin-top:5px;height:450px; overflow:scroll;">
                <apex:pageBlockTable id="table1" value="{!quoteList}" var="quotes" >
                <apex:column >
                <apex:facet name="header">Name</apex:facet>
                 <a href="#" onClick="window.parent.location.href='/{!quotes.Id}'">{!quotes.Name}</a>   
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Quote Number</apex:facet>
                 <a href="#" onClick="window.parent.location.href='/{!quotes.Id}'">{!quotes.QuoteNumber}</a>   
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Account Name</apex:facet>
                <a href="#" onClick="window.parent.location.href='/{!quotes.Opportunity.Account.Id}'">{!quotes.Opportunity.Account.name}</a>
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Opportunity Name</apex:facet>
                <a href="#" onClick="window.parent.location.href='/{!quotes.Opportunity.Id}'">{!quotes.Opportunity.name}</a>
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Status</apex:facet>
                {!quotes.Status}
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Expiration Date</apex:facet>
                <apex:outputText value="{0,date,MM/dd/yyyy}">
                        <apex:param value="{!quotes.ExpirationDate}"/>
                    </apex:outputText>  
                </apex:column>
  
                <apex:column ><apex:facet name="header">Grand Total</apex:facet>
                <apex:outputText value="{0, number, currency}">
                        <apex:param value="{!quotes.GrandTotal}"/>
                    </apex:outputText> 
                </apex:column>
           
                </apex:pageBlockTable>
                </div>
         </apex:pageBlock>
    </apex:form>
</apex:page>

SC class

public class QuotePgeCtrl
{
   
    public Id quoteId {get;set;}
    public QuotePgeCtrl(ApexPages.StandardController controller)
    {
        sObject quote = controller.getRecord();
        quoteId = (Id) quote.get('Id');
    }

    public string quotevalue{get; set;}
    public list<Quote> quoteList{get; set;}
    public list<Quote> getreviewdqt()
    {
        if(quotevalue == 'None')
       {
            quoteList= new list<Quote>([SELECT Opportunity.Account.Name, QuoteNumber, GrandTotal, Opportunity.name,OpportunityId, Name, IsSyncing, Id, Status,ExpirationDate From Quote WHERE Status ='None']);
      }
       if(quotevalue == 'Draft Quotes')
       {
           quoteList= new list<Quote>([SELECT Opportunity.Account.Name, QuoteNumber, GrandTotal, Opportunity.name,OpportunityId, Name, IsSyncing, Id, Status,ExpirationDate From Quote WHERE Status ='Draft']);
      }
       if(quotevalue == 'Accepted Quotes')
       {
            quoteList= new list<Quote>([SELECT Opportunity.Account.Name, QuoteNumber, GrandTotal, Opportunity.name,OpportunityId, Name, IsSyncing, Id, Status,ExpirationDate From Quote WHERE Status ='Accepted']);
       }
        if(quotevalue == 'Review Pending Quotes')
       {
            quoteList= new list<Quote>([SELECT Opportunity.Account.Name, QuoteNumber, GrandTotal, Opportunity.name,OpportunityId, Name, IsSyncing, Id, Status,ExpirationDate From Quote WHERE Status ='Review Pending']);
       }
      return null;
     }
 }

Test Class
@isTest
public class QuotePgeCtrlTestClass
{
    static testMethod void testMethod1()
    {
        string quotevalue = 'Draft Quotes';
        Quote testQuote = new Quote();
        testQuote.Name='TestQuote' ;
        testQuote.ExpirationDate = system.today();
        testQuote.Status = 'Draft';
        testQuote.OpportunityId = '0066300000341BJ' ;
        System.debug('******************Inserting the record...');
        insert testQuote;
       Test.StartTest();
       
       ApexPages.StandardController sc = new ApexPages.StandardController(testQuote);
        QuotePgeCtrl testQt = new QuotePgeCtrl(sc);
      list<Quote> obj = testQt.getreviewdqt();
       Test.StopTest();
}

What is missign in the code ?

Thanks & regards,
Pallavi
  • September 30, 2016
  • Like
  • 0
Hi ,

I have created a custom VF page to dipsplay list of quotes based on the quote status which is working but the Code coverage on test class is just 68%. 
VF Code
<apex:page StandardController="Quote" extensions="QuotePgeCtrl" sidebar="true" tabStyle="HPQuotes__tab">
    <html>
    <div class="blank">&nbsp;</div>
    <div class="content"><img src="/s.gif" class="pageTitleIcon" title="Quote"/>
    <h1>Quotes</h1><br>
    <font size="5">Home</font></br>
    <div class="blank">&nbsp;</div>
    </div></html>
     
    <apex:form >
        <apex:pageBlock title="Recent Quotes">
                <b>View:  </b>
                <apex:selectList size="1" value="{!quotevalue}">
                <apex:actionSupport event="onchange" action="{!getreviewdqt}" rerender="table1"/>
                <apex:selectOption itemLabel="None" itemValue="None"></apex:selectOption>
                <apex:selectOption itemLabel="Draft Quotes" itemValue="Draft Quotes"></apex:selectOption>
                <apex:selectOption itemLabel="Accepted Quotes" itemValue="Accepted Quotes"></apex:selectOption>
                <apex:selectOption itemLabel="Review Pending Quotes" itemValue="Review Pending Quotes"></apex:selectOption>
                </apex:selectList>
                
               <div style="width:100%; margin-top:5px;height:450px; overflow:scroll;">
                <apex:pageBlockTable id="table1" value="{!quoteList}" var="quotes" >
                <apex:column >
                <apex:facet name="header">Name</apex:facet>
                 <a href="#" onClick="window.parent.location.href='/{!quotes.Id}'">{!quotes.Name}</a>   
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Quote Number</apex:facet>
                 <a href="#" onClick="window.parent.location.href='/{!quotes.Id}'">{!quotes.QuoteNumber}</a>   
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Account Name</apex:facet>
                <a href="#" onClick="window.parent.location.href='/{!quotes.Opportunity.Account.Id}'">{!quotes.Opportunity.Account.name}</a>
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Opportunity Name</apex:facet>
                <a href="#" onClick="window.parent.location.href='/{!quotes.Opportunity.Id}'">{!quotes.Opportunity.name}</a>
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Status</apex:facet>
                {!quotes.Status}
                </apex:column>
                
                <apex:column >
                <apex:facet name="header">Expiration Date</apex:facet>
                <apex:outputText value="{0,date,MM/dd/yyyy}">
                        <apex:param value="{!quotes.ExpirationDate}"/>
                    </apex:outputText>  
                </apex:column>
  
                <apex:column ><apex:facet name="header">Grand Total</apex:facet>
                <apex:outputText value="{0, number, currency}">
                        <apex:param value="{!quotes.GrandTotal}"/>
                    </apex:outputText> 
                </apex:column>
           
                </apex:pageBlockTable>
                </div>
         </apex:pageBlock>
    </apex:form>
</apex:page>

SC class

public class QuotePgeCtrl
{
   
    public Id quoteId {get;set;}
    public QuotePgeCtrl(ApexPages.StandardController controller)
    {
        sObject quote = controller.getRecord();
        quoteId = (Id) quote.get('Id');
    }

    public string quotevalue{get; set;}
    public list<Quote> quoteList{get; set;}
    public list<Quote> getreviewdqt()
    {
        if(quotevalue == 'None')
       {
            quoteList= new list<Quote>([SELECT Opportunity.Account.Name, QuoteNumber, GrandTotal, Opportunity.name,OpportunityId, Name, IsSyncing, Id, Status,ExpirationDate From Quote WHERE Status ='None']);
      }
       if(quotevalue == 'Draft Quotes')
       {
           quoteList= new list<Quote>([SELECT Opportunity.Account.Name, QuoteNumber, GrandTotal, Opportunity.name,OpportunityId, Name, IsSyncing, Id, Status,ExpirationDate From Quote WHERE Status ='Draft']);
      }
       if(quotevalue == 'Accepted Quotes')
       {
            quoteList= new list<Quote>([SELECT Opportunity.Account.Name, QuoteNumber, GrandTotal, Opportunity.name,OpportunityId, Name, IsSyncing, Id, Status,ExpirationDate From Quote WHERE Status ='Accepted']);
       }
        if(quotevalue == 'Review Pending Quotes')
       {
            quoteList= new list<Quote>([SELECT Opportunity.Account.Name, QuoteNumber, GrandTotal, Opportunity.name,OpportunityId, Name, IsSyncing, Id, Status,ExpirationDate From Quote WHERE Status ='Review Pending']);
       }
      return null;
     }
 }

Test Class
@isTest
public class QuotePgeCtrlTestClass
{
    static testMethod void testMethod1()
    {
        string quotevalue = 'Draft Quotes';
        Quote testQuote = new Quote();
        testQuote.Name='TestQuote' ;
        testQuote.ExpirationDate = system.today();
        testQuote.Status = 'Draft';
        testQuote.OpportunityId = '0066300000341BJ' ;
        System.debug('******************Inserting the record...');
        insert testQuote;
       Test.StartTest();
       
       ApexPages.StandardController sc = new ApexPages.StandardController(testQuote);
        QuotePgeCtrl testQt = new QuotePgeCtrl(sc);
      list<Quote> obj = testQt.getreviewdqt();
       Test.StopTest();
}

What is missign in the code ?

Thanks & regards,
Pallavi
  • September 30, 2016
  • Like
  • 0