You need to sign in to do that
Don't have an account?
sujit admin
Please help me in test class for visualforce page controller
VF page:
<apex:page standardController="Account" extensions="LH_PartnerOnCompanyExtsn" title="New BillTo" showHeader="false" >
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<apex:stylesheet value="{!URLFOR($Resource.SLDS0122, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
<!--<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"/>
<script type="text/javascript" >
$j = jQuery.noConflict();
$j(document).ready(function()
{
$j('a').attr("target","_blank");
});
</script>-->
</head>
<div class="slds slds-scrollable">
<apex:form id="form">
<!--<div class="slds-button" id="saveAction1">
</div>-->
<!-- PAGE HEADER -->
<div class="" style="margin-bottom:10px; !important;" role="banner">
<!-- LAYOUT GRID -->
<div class="slds-grid">
<!-- GRID COL -->
<div class="slds-col--padded slds-size--1-of-4">
</div>
<div class="slds-col--padded slds-size--3-of-4">
<!-- HEADING AREA -->
<apex:commandButton value="New Bill-To" onclick="window.open('{!billtoredirect}','_parent');" style="margin-right:5px; !important;" styleclass="slds-button--neutral"/>
<apex:commandButton value="Add" onclick="window.open('{!Addbillto}','_parent');" styleclass="slds-button--neutral" />
</div>
</div>
<!-- / LAYOUT GRID -->
</div>
<!-- / PAGE HEADER -->
<div class="myapp">
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr class="slds-text-heading--label">
<th scope="col" title="Opportunity Name">
<div class="slds-truncate">Bill-To Name</div>
</th>
<th scope="col" title="CRM Company Number">
<div class="slds-truncate">CRM Company Number</div>
</th>
<th scope="col" title="Address">
<div class="slds-truncate">SAP No</div>
</th>
</tr>
</thead>
<tbody>
<apex:repeat value="{!BillToList}" var="p">
<tr>
<!--<td data-label="Account Name" title="Account Name">
<div class="slds-truncate">{!p.Business_Partner__r.Name}</div>
</td>-->
<td data-label="Account Name" title="Company__c">
<div class="slds-truncate">
<!--<apex:outputLink value="/{!p.Company__c}">{!p.Business_Partner__r.Name}</apex:outputLink>-->
<a href="/{!p.business_partner__c}" target="__blank">{!p.Business_Partner__r.Name}</a>
</div>
</td>
<td data-label="Account Name" title="Company__c">
<div class="slds-truncate">{!p.Business_Partner__r.CRM_Company_No__c}</div>
</td>
<td data-label="Account Name" title="Id">
<div class="slds-truncate">{!p.Business_Partner__r.SAP_No__c} </div>
</td>
</tr>
</apex:repeat>
</tbody>
</table>
</div>
</apex:form>
</div>
</html>
</apex:page>
Controller class:
/*
Change Log
1/8/206 : - Added by Suresh to displaying Business Partner(Ship-to, Bill-To and Payer) on Company Level
*/
public class LH_PartnerOnCompanyExtsn {
public List<business_partner__c> BillToList{get;set;}
public List<business_partner__c> ShipToList{get;set;}
public List<business_partner__c> PayerToList{get;set;}
// public List<business_partner__c> customerofshiptoList{get;set;}
public PageReference shiptoredirect{get;set;}
public PageReference billtoredirect{get;set;}
public PageReference payertoredirect{get;set;}
public PageReference Addbillto{get;set;}
public PageReference Addshipto{get;set;}
public PageReference Addpayerto{get;set;}
//public PageReference AddcustomertoshipTo{get;set;}
// public PageReference Addcustomeronbillto{get;set;}
//public PageReference Addcustomeronpayer{get;set;}
Public Account Acc{get;set;}
Public Id recTypeId_ship_to;
Public Id recTypeId_bill_to;
Public Id recTypeId_Payer;
Public Id recTypeId_Customer;
Public Id businessPartnerShipToRecType;
Public Id businessPartnerBillToRecType;
Public Id businessPartnerPayerRecType;
Public Id businessPartnerAccountRecType;
public LH_PartnerOnCompanyExtsn(ApexPages.StandardController controller) {
Acc = (Account)controller.getRecord();
recTypeId_ship_to = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Ship-to').getRecordTypeId();
recTypeId_bill_to = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Bill-To Only').getRecordTypeId();
recTypeId_Payer = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Payer Only').getRecordTypeId();
recTypeId_Customer= Schema.SObjectType.Account.getRecordTypeInfosByName().get('Customer').getRecordTypeId();
businessPartnerShipToRecType =Schema.SObjectType.Business_Partner__c.getRecordTypeInfosByName().get('Ship-To').getRecordTypeId();
businessPartnerBillToRecType =Schema.SObjectType.Business_Partner__c.getRecordTypeInfosByName().get('Bill-To').getRecordTypeId();
businessPartnerPayerRecType =Schema.SObjectType.Business_Partner__c.getRecordTypeInfosByName().get('Payer Only').getRecordTypeId();
ShipToList=[SELECT Id,name,company__c,Business_Partner__r.SAP_No__c,Business_Partner__r.CRM_Company_No__c,Business_Partner__r.Name,business_partner__c,Company__r.Name,Company__r.CRM_Company_No__c,Company__r.SAP_No__c,Company__r.Company_Type__c,business_partner__r.Address__r.Name FROM Business_Partner__c WHERE Company__c =: Acc.Id and recordtypeid =:businessPartnerShipToRecType];
BillToList=[SELECT Id,name,company__c,Business_Partner__r.SAP_No__c,Business_Partner__r.CRM_Company_No__c,Business_Partner__r.Name,business_partner__c,Company__r.Name,Company__r.CRM_Company_No__c,Company__r.SAP_No__c,Company__r.Company_Type__c ,business_partner__r.Address__r.Name FROM Business_Partner__c WHERE Company__c =: Acc.Id and recordtypeid =:businessPartnerBillToRecType];
PayerToList=[SELECT Id,name,company__c,Business_Partner__r.SAP_No__c,Business_Partner__r.CRM_Company_No__c,Business_Partner__r.Name,business_partner__c,Company__r.Name,Company__r.CRM_Company_No__c,Company__r.SAP_No__c,Company__r.Company_Type__c ,business_partner__r.Address__r.Name FROM Business_Partner__c WHERE Company__c =: Acc.Id and recordtypeid =:businessPartnerPayerRecType];
//customerofshiptoList=[SELECT Id,name,Business_Partner__r.Name,business_partner__c,Company__r.Name,Company__r.CRM_Company_No__c,Company__r.SAP_No__c,Company__r.Company_Type__c,Company__r.Address__r.Name FROM Business_Partner__c WHERE Business_Partner__c =: Acc.Id and recordtypeid =:businessPartnerShipToRecType];
redirect();
}
public void redirect(){
PageReference BillToPage = new PageReference('/apex/LH_CreateNewBillTo_LightningNew?rectypeid='+recTypeId_bill_to+'&billAccId='+Acc.id+'&type=newbilltofromcompany').setRedirect(true);
billtoredirect = BillToPage;
PageReference shipToPage = new PageReference('/apex/LH_CreateShipTo_Lightning_New?rectypeid='+recTypeId_ship_to+'&shipAccId='+Acc.id+'&type=newshiptofromcompany').setRedirect(true);
shiptoredirect = shipToPage;
PageReference payerPage = new PageReference('/apex/LH_CreateNewPayer_LightningNew?rectypeid='+recTypeId_Payer+'&payerAccId='+Acc.id+'&type=newpayertofromcompany').setRedirect(true);
payertoredirect = payerPage;
PageReference AddbilltoPage = new PageReference('/apex/LH_AddPartnerToCompany?recid='+recTypeId_bill_to+'&AccId='+Acc.id).setRedirect(true);
Addbillto = AddbilltoPage ;
PageReference AddshiptoPage = new PageReference('/apex/LH_AddPartnerToCompany?recid='+recTypeId_ship_to+'&AccId='+Acc.id).setRedirect(true);
Addshipto = AddshiptoPage ;
PageReference AddpayertoPage = new PageReference('/apex/LH_AddPartnerToCompany?recid='+recTypeId_Payer+'&AccId='+Acc.id).setRedirect(true);
Addpayerto = AddpayertoPage ;
// PageReference AddcustomertoshipToPage = new PageReference('/apex/LH_AddPartnerToCompany?recid='+recTypeId_ship_to+'&AccId='+Acc.id+'&type=addcompanytopartner').setRedirect(true);
// AddcustomertoshipTo = AddcustomertoshipToPage ;
}
}
please write a test class for this class....
<apex:page standardController="Account" extensions="LH_PartnerOnCompanyExtsn" title="New BillTo" showHeader="false" >
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<apex:stylesheet value="{!URLFOR($Resource.SLDS0122, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
<!--<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"/>
<script type="text/javascript" >
$j = jQuery.noConflict();
$j(document).ready(function()
{
$j('a').attr("target","_blank");
});
</script>-->
</head>
<div class="slds slds-scrollable">
<apex:form id="form">
<!--<div class="slds-button" id="saveAction1">
</div>-->
<!-- PAGE HEADER -->
<div class="" style="margin-bottom:10px; !important;" role="banner">
<!-- LAYOUT GRID -->
<div class="slds-grid">
<!-- GRID COL -->
<div class="slds-col--padded slds-size--1-of-4">
</div>
<div class="slds-col--padded slds-size--3-of-4">
<!-- HEADING AREA -->
<apex:commandButton value="New Bill-To" onclick="window.open('{!billtoredirect}','_parent');" style="margin-right:5px; !important;" styleclass="slds-button--neutral"/>
<apex:commandButton value="Add" onclick="window.open('{!Addbillto}','_parent');" styleclass="slds-button--neutral" />
</div>
</div>
<!-- / LAYOUT GRID -->
</div>
<!-- / PAGE HEADER -->
<div class="myapp">
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr class="slds-text-heading--label">
<th scope="col" title="Opportunity Name">
<div class="slds-truncate">Bill-To Name</div>
</th>
<th scope="col" title="CRM Company Number">
<div class="slds-truncate">CRM Company Number</div>
</th>
<th scope="col" title="Address">
<div class="slds-truncate">SAP No</div>
</th>
</tr>
</thead>
<tbody>
<apex:repeat value="{!BillToList}" var="p">
<tr>
<!--<td data-label="Account Name" title="Account Name">
<div class="slds-truncate">{!p.Business_Partner__r.Name}</div>
</td>-->
<td data-label="Account Name" title="Company__c">
<div class="slds-truncate">
<!--<apex:outputLink value="/{!p.Company__c}">{!p.Business_Partner__r.Name}</apex:outputLink>-->
<a href="/{!p.business_partner__c}" target="__blank">{!p.Business_Partner__r.Name}</a>
</div>
</td>
<td data-label="Account Name" title="Company__c">
<div class="slds-truncate">{!p.Business_Partner__r.CRM_Company_No__c}</div>
</td>
<td data-label="Account Name" title="Id">
<div class="slds-truncate">{!p.Business_Partner__r.SAP_No__c} </div>
</td>
</tr>
</apex:repeat>
</tbody>
</table>
</div>
</apex:form>
</div>
</html>
</apex:page>
Controller class:
/*
Change Log
1/8/206 : - Added by Suresh to displaying Business Partner(Ship-to, Bill-To and Payer) on Company Level
*/
public class LH_PartnerOnCompanyExtsn {
public List<business_partner__c> BillToList{get;set;}
public List<business_partner__c> ShipToList{get;set;}
public List<business_partner__c> PayerToList{get;set;}
// public List<business_partner__c> customerofshiptoList{get;set;}
public PageReference shiptoredirect{get;set;}
public PageReference billtoredirect{get;set;}
public PageReference payertoredirect{get;set;}
public PageReference Addbillto{get;set;}
public PageReference Addshipto{get;set;}
public PageReference Addpayerto{get;set;}
//public PageReference AddcustomertoshipTo{get;set;}
// public PageReference Addcustomeronbillto{get;set;}
//public PageReference Addcustomeronpayer{get;set;}
Public Account Acc{get;set;}
Public Id recTypeId_ship_to;
Public Id recTypeId_bill_to;
Public Id recTypeId_Payer;
Public Id recTypeId_Customer;
Public Id businessPartnerShipToRecType;
Public Id businessPartnerBillToRecType;
Public Id businessPartnerPayerRecType;
Public Id businessPartnerAccountRecType;
public LH_PartnerOnCompanyExtsn(ApexPages.StandardController controller) {
Acc = (Account)controller.getRecord();
recTypeId_ship_to = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Ship-to').getRecordTypeId();
recTypeId_bill_to = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Bill-To Only').getRecordTypeId();
recTypeId_Payer = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Payer Only').getRecordTypeId();
recTypeId_Customer= Schema.SObjectType.Account.getRecordTypeInfosByName().get('Customer').getRecordTypeId();
businessPartnerShipToRecType =Schema.SObjectType.Business_Partner__c.getRecordTypeInfosByName().get('Ship-To').getRecordTypeId();
businessPartnerBillToRecType =Schema.SObjectType.Business_Partner__c.getRecordTypeInfosByName().get('Bill-To').getRecordTypeId();
businessPartnerPayerRecType =Schema.SObjectType.Business_Partner__c.getRecordTypeInfosByName().get('Payer Only').getRecordTypeId();
ShipToList=[SELECT Id,name,company__c,Business_Partner__r.SAP_No__c,Business_Partner__r.CRM_Company_No__c,Business_Partner__r.Name,business_partner__c,Company__r.Name,Company__r.CRM_Company_No__c,Company__r.SAP_No__c,Company__r.Company_Type__c,business_partner__r.Address__r.Name FROM Business_Partner__c WHERE Company__c =: Acc.Id and recordtypeid =:businessPartnerShipToRecType];
BillToList=[SELECT Id,name,company__c,Business_Partner__r.SAP_No__c,Business_Partner__r.CRM_Company_No__c,Business_Partner__r.Name,business_partner__c,Company__r.Name,Company__r.CRM_Company_No__c,Company__r.SAP_No__c,Company__r.Company_Type__c ,business_partner__r.Address__r.Name FROM Business_Partner__c WHERE Company__c =: Acc.Id and recordtypeid =:businessPartnerBillToRecType];
PayerToList=[SELECT Id,name,company__c,Business_Partner__r.SAP_No__c,Business_Partner__r.CRM_Company_No__c,Business_Partner__r.Name,business_partner__c,Company__r.Name,Company__r.CRM_Company_No__c,Company__r.SAP_No__c,Company__r.Company_Type__c ,business_partner__r.Address__r.Name FROM Business_Partner__c WHERE Company__c =: Acc.Id and recordtypeid =:businessPartnerPayerRecType];
//customerofshiptoList=[SELECT Id,name,Business_Partner__r.Name,business_partner__c,Company__r.Name,Company__r.CRM_Company_No__c,Company__r.SAP_No__c,Company__r.Company_Type__c,Company__r.Address__r.Name FROM Business_Partner__c WHERE Business_Partner__c =: Acc.Id and recordtypeid =:businessPartnerShipToRecType];
redirect();
}
public void redirect(){
PageReference BillToPage = new PageReference('/apex/LH_CreateNewBillTo_LightningNew?rectypeid='+recTypeId_bill_to+'&billAccId='+Acc.id+'&type=newbilltofromcompany').setRedirect(true);
billtoredirect = BillToPage;
PageReference shipToPage = new PageReference('/apex/LH_CreateShipTo_Lightning_New?rectypeid='+recTypeId_ship_to+'&shipAccId='+Acc.id+'&type=newshiptofromcompany').setRedirect(true);
shiptoredirect = shipToPage;
PageReference payerPage = new PageReference('/apex/LH_CreateNewPayer_LightningNew?rectypeid='+recTypeId_Payer+'&payerAccId='+Acc.id+'&type=newpayertofromcompany').setRedirect(true);
payertoredirect = payerPage;
PageReference AddbilltoPage = new PageReference('/apex/LH_AddPartnerToCompany?recid='+recTypeId_bill_to+'&AccId='+Acc.id).setRedirect(true);
Addbillto = AddbilltoPage ;
PageReference AddshiptoPage = new PageReference('/apex/LH_AddPartnerToCompany?recid='+recTypeId_ship_to+'&AccId='+Acc.id).setRedirect(true);
Addshipto = AddshiptoPage ;
PageReference AddpayertoPage = new PageReference('/apex/LH_AddPartnerToCompany?recid='+recTypeId_Payer+'&AccId='+Acc.id).setRedirect(true);
Addpayerto = AddpayertoPage ;
// PageReference AddcustomertoshipToPage = new PageReference('/apex/LH_AddPartnerToCompany?recid='+recTypeId_ship_to+'&AccId='+Acc.id+'&type=addcompanytopartner').setRedirect(true);
// AddcustomertoshipTo = AddcustomertoshipToPage ;
}
}
please write a test class for this class....
Please refer to Testing Custom Controllers and Controller Extensions (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm)
I'm not sure if anyone is going to write a Unit Test Class on your behalf, moreover its a good habit to learn doing tasks on your own.
Happy Learning !!!