/*Author: Krishna Yerru
* DATE:8/23/2019
* Description: Test class for BIIB_Contact_SearchController
* */
@istest
public class BIIB_Contact_SearchController_Test {
Public static testmethod void SearchContactTest(){
Test.startTest();
account acc=new account(name='test');
insert acc;
contact con=new contact(lastname='test_con_V1');
insert con;
system.assertequals(con.lastName,'test_con_V1');
ApexPages.StandardController sc = new ApexPages.StandardController(con);
BIIB_Contact_SearchController CS=new BIIB_Contact_SearchController(sc);
BIIB_Contact_SearchController.BIIB_MyWrapCls ws=new BIIB_Contact_SearchController.BIIB_MyWrapCls(con);
CS.BIIB_method();
CS.BIIB_Detailmethod();
Test.stopTest();
}
Public static testmethod void SearchContactTest2(){
Test.startTest();
account acc=new account(name='test1234');
insert acc;
contact con=new contact(lastname='test_con_V2');
insert con;
PageReference pageRef = Page.BIIB_Contact_SearchPage;
Test.setCurrentPage(pageRef);
String BIIB_searchCont='searchkey';
boolean BIIB_flag=true;
system.assertequals(con.lastName,'test_con_V2');
ApexPages.StandardController sc = new ApexPages.StandardController(acc);
BIIB_Contact_SearchController CS=new BIIB_Contact_SearchController(sc);
BIIB_Contact_SearchController.BIIB_MyWrapCls ws=new BIIB_Contact_SearchController.BIIB_MyWrapCls(con);
CS.BIIB_method();
CS.BIIB_Detailmethod();
Test.stopTest();
}
}
******************
* DATE:8/23/2019
* Description: Test class for BIIB_Contact_SearchController
* */
@istest
public class BIIB_Contact_SearchController_Test {
Public static testmethod void SearchContactTest(){
Test.startTest();
account acc=new account(name='test');
insert acc;
contact con=new contact(lastname='test_con_V1');
insert con;
system.assertequals(con.lastName,'test_con_V1');
ApexPages.StandardController sc = new ApexPages.StandardController(con);
BIIB_Contact_SearchController CS=new BIIB_Contact_SearchController(sc);
BIIB_Contact_SearchController.BIIB_MyWrapCls ws=new BIIB_Contact_SearchController.BIIB_MyWrapCls(con);
CS.BIIB_method();
CS.BIIB_Detailmethod();
Test.stopTest();
}
Public static testmethod void SearchContactTest2(){
Test.startTest();
account acc=new account(name='test1234');
insert acc;
contact con=new contact(lastname='test_con_V2');
insert con;
PageReference pageRef = Page.BIIB_Contact_SearchPage;
Test.setCurrentPage(pageRef);
String BIIB_searchCont='searchkey';
boolean BIIB_flag=true;
system.assertequals(con.lastName,'test_con_V2');
ApexPages.StandardController sc = new ApexPages.StandardController(acc);
BIIB_Contact_SearchController CS=new BIIB_Contact_SearchController(sc);
BIIB_Contact_SearchController.BIIB_MyWrapCls ws=new BIIB_Contact_SearchController.BIIB_MyWrapCls(con);
CS.BIIB_method();
CS.BIIB_Detailmethod();
Test.stopTest();
}
}
******************
<!--
*
* @Author: Krishna Yerru
* @Date: 8/23/2019
* @ Description: Search the contact records using text field
*
-->
<apex:page standardController="Contact" extensions="BIIB_Contact_SearchController" tabStyle="Contact" sidebar="false">
<apex:form id="frm">
<apex:pageBlock id="PB">
<apex:pageMessages > </apex:pageMessages>
<div style="text-align:center;font-size: 18px; font-weight: bold ;">
<apex:outputText style="text-align:center; font-weight: bold ;" value="Welcome to Contact Search Page"></apex:outputText>
</div>
<div> </div>
<div style="text-align:left;font-size: 11px; font-weight: bold ;">
<apex:pageBlockSection >
<apex:pageBlockSectionItem helpText="Please give search keyword">
<apex:outputText style="text-align:center; font-weight: bold ;" value="SEARCH CONTACT RECORDS :"></apex:outputText>
<apex:inputText required="true" value="{!BIIB_searchCont}" label="Please give search keyword"/>
</apex:pageBlockSectionItem>
<apex:commandButton value="Search" action="{!BIIB_method}" id="srch" style="float:center"/>
</apex:pageBlockSection>
</div>
<apex:pageBlockSection title="Contact Records" rendered="{!(Searchkey == false)}" id="ee1">
<apex:outputLabel value="No Contact found Please Use Contact Last Name as Search key"></apex:outputLabel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Contact Records" columns="1" rendered="{!(Searchkey != false)}">
<apex:pageBlockTable value="{!BIIB_MyList}" align="Centre" var="contactTable">
<apex:column ><apex:inputCheckbox value="{!contactTable.BIIB_flag}"/></apex:column>
<apex:column value="{!contactTable.BIIB_conWrap.name}" />
<apex:column value="{!contactTable.BIIB_conWrap.email}" />
<apex:column value="{!contactTable.BIIB_conWrap.Phone}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<div style="text-align: center">
<apex:commandButton value="See Results" action="{!BIIB_Detailmethod}" style="float:center" reRender="ee" />
</div>
<apex:pageBlockSection title="Searched Contact Details" rendered="{!(Searchkey != false)}" columns="1" id="ee">
<apex:pageBlockTable value="{!BIIB_selectedlist}" align="Centre" columns="5" var="scon">
<apex:column value="{!scon.id}"/>
<apex:column value="{!scon.name}" />
<apex:column value="{!scon.email}" />
<apex:column value="{!scon.Phone}" />
<apex:column value="{!scon.AccountID}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
****************************
/* * @Author: Krishna yerru * @Date: 8/23/2019 * @ Description: Control class of Contact Search VF Page * @ Testclass: */ public class BIIB_Contact_SearchController { public List<BIIB_MyWrapCls> BIIB_MyList {get;set;} public List<contact> BIIB_conList{get;set;} public String BIIB_searchCont {get;set;} public List<contact> BIIB_selectedlist {get;set;} public boolean Searchkey{ get; set; } //Constructor for the class public BIIB_Contact_SearchController (ApexPages.StandardController controller){ BIIB_Mylist = new List<BIIB_MyWrapCls>(); BIIB_conList = new List<Contact>(); BIIB_selectedlist=new List<Contact>(); BIIB_searchCont=''; Searchkey = false; } //Search the contacts through the below method public void BIIB_method(){ BIIB_Mylist=new list <BIIB_MyWrapCls>(); BIIB_conList = new List<Contact>(); //Searchkey = false; //BIIB_Mylist.clear(); // apexpages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please Provide Last name of Contact')); string s='%'+BIIB_searchCont+'%'; string sql='select id,name,lastname,email,phone,account.name,accountid from contact where Lastname like:s'; BIIB_conList=database.query(sql); if(BIIB_conList.size()>0){ for(contact scl:BIIB_conList){ BIIB_Mylist.add(new BIIB_MyWrapCls(scl)); } } else if(BIIB_Mylist.size()<0){ Searchkey = false;} if(BIIB_Mylist.size()>0){ Searchkey = true; } } //This methos is used for get the selected contacts Public void BIIB_Detailmethod(){ BIIB_selectedlist=new List<Contact>(); for(BIIB_MyWrapCls wa:BIIB_Mylist){ if(wa.BIIB_flag==true){ BIIB_selectedlist.add(wa.BIIB_conWrap); } } } //wrapper class public class BIIB_MyWrapCls{ public boolean BIIB_flag {get;set;} public Contact BIIB_conWrap {get;set;} public BIIB_MyWrapCls(contact c) { this.BIIB_conWrap=c; this.BIIB_flag=false; } } }
************************
No comments:
Post a Comment