You need to sign in to do that
Don't have an account?
Desai
Code coverage for Standard controller test class
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"> </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"> </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
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"> </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"> </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
Please try Below code you get 100% code coverage....
Thanks & Cheers.
Jakin
All Answers
You will find which part isn't be covered(not in blue color).
Hope it will a help.
Best,
Huanghttps://randsfdc.blogspot.com (https://randsfdc.blogspot.com" target="_blank)
testQuote.OpportunityId = '0066300000341BJ' ;
is not acceptable because we can't assign hardcoded id for a record.For OpportunityId you have to first create a opportunity record then insert it and then assign this opportunity id to testQuote.OpportunityId.
Regards
Banwari kevat
Please try Below code you get 100% code coverage....
Thanks & Cheers.
Jakin
Thanks for inputs. Above code is perfect.
Regards,
Pallavi
You'r Welcome any time ☺...
Thanks,
Jakin