Monday 21 May 2018

One particular lead takes how many days to change it's stage from one stage value to another

/***************
Ceated By    : Mohit Dwivedi(KVP Business Solution Pvt Ltd).
Created Date : 
Purpose      : This controller is for Lead Age Report.

***************/

public class leadReportController{
    public Date fromDate {get;set;}
    public Date toDate {get;set;}
    public Boolean showHideTable{get;set;}
    public List<wrapLead> wrapList{get;set;}
    public Integer openCountRecord{get;set;}
    public Integer CallBackCountRecord{get;set;}
    public Integer ContactedCountRecord{get;set;}
    public Integer FirmCountRecord{get;set;}
    public Integer LostCountRecord{get;set;}
    public Integer NotIntrestedCountRecord{get;set;}
    public Integer OthersCountRecord{get;set;}
    public Integer QualifiedCountRecord{get;set;}
    public Integer UnqualifiedCountRecord{get;set;}
    public Decimal openCountWrap {get;set;}
    public Decimal CallBackCountWrap {get;set;}
    public Decimal ContactedCountWrap {get;set;}
    public Decimal FirmCountWrap {get;set;}
    public Decimal LostCountWrap {get;set;}
    public Decimal NotIntrestedCountWrap {get;set;}
    public Decimal OthersCountWrap {get;set;}
    public Decimal QualifiedCountWrap {get;set;}
    public Decimal UnqualifiedCountWrap {get;set;}
    public boolean showhidetable2{get;set;}
    public boolean Flag{get;set;}
    public List<SelectOption> LeadJunList{get;set;}
    public String selectedSource{get;set;}
    public list<Wrapperclass> wrapperlistdata;
    public string AllstagesData{get;set;}
    public boolean showhide{get;set;}
    public String stagenames{get;set;}
    
    public leadReportController(){
        showHideTable2=false;
        showhide=false;
        showHideTable = false;
        wrapList = new list<wrapLead>();
        wrapperlistdata =new list<Wrapperclass>();
        Set<String> sourceSet = new Set<String>();
        LeadJunList = new List<SelectOption>();     
        Schema.DescribeFieldResult fieldResult = Lead.LeadSource.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       // displayLeadTable();
                
           for( Schema.PicklistEntry f : ple)
           {
             sourceSet.add(f.getLabel());
           }       
      
        system.debug('------------sourceSet----------'+sourceSet);
        
        LeadJunList.add(new SelectOption('-None-', '-None-'));
        //LeadJunList.add(new SelectOption('All', 'All'));
        for(String Source : sourceSet){
            LeadJunList.add(new SelectOption(Source, Source));
        }
    }
   
    
    public void displayLeadTable() {
        
        showHideTable2=true;
        showhide=true;
        map<String,double> stagenamesmap=new map<String,decimal>{'open'=>0,'CallBack'=>0,'Contacted'=>0,'Firm Enquiry'=>0,'Lost'=>0,'Not Interested'=>0,'Others'=>0,'Qualified'=>0,'Unqualified'=>0};
        map<String,double> mapofstageswithdata =new map<String,decimal>();
        map<String,double> mapofStatuscount = new map<String,decimal>();
        list<Decimal> statuscountlist = new list<Decimal>();
        list<Decimal> stagenameslist =new list<Decimal>();
        
        
        
        wrapperlistdata.clear();
        if(wrapList.size() >0){
            wrapList.clear();
        }
        wrapList = new list<wrapLead>();
        wrapperlistdata =new list<Wrapperclass>();
        List<Lead_Junction__c> ljList = new list<Lead_Junction__c>();
        Integer openCount = 0;
        Integer CallBackCount = 0;
        Integer ContactedCount = 0;
        Integer FirmCount = 0;
        Integer LostCount = 0;
        Integer NotIntrestedCount = 0;
        Integer OthersCount = 0;
        Integer QualifiedCount = 0;
        Integer UnqualifiedCount = 0;
        Decimal TotalOpenCount = 0;
        Decimal TotalCallBackCount = 0;
        Decimal TotalContactedCount = 0;
        Decimal TotalFirmCount = 0;
        Decimal TotalLostCount = 0;
        Decimal TotalNotIntrestedCount = 0;
        Decimal TotalOthersCount = 0;
        Decimal TotalQualifiedCount = 0;
        Decimal TotalUnqualifiedCount = 0;
        
        system.debug('----------fromDate--------'+fromDate);
        system.debug('----------toDate--------'+toDate);
        
        if(fromDate ==null && toDate == null){
            showHideTable = False;
            flag =showHideTable ;
        }else if(fromDate !=null && toDate != null){
            ljList = [SELECT Name,Lead_Current_Status__c,LeadPrevious_Status__c,lead_sources__c,Total_Days_in_same_Status__c FROM Lead_Junction__c WHERE Total_Days_in_same_Status__c!= null AND DAY_ONLY(convertTimezone(CreatedDate)) >= : fromDate AND DAY_ONLY(convertTimezone(CreatedDate)) <= : toDate AND lead_sources__c =: selectedSource ];
            system.debug('----------ljList(else)--------'+ljList);
        }
        if(test.isRunningTest()){
           ljList = [SELECT Name,Lead_Current_Status__c,LeadPrevious_Status__c,lead_sources__c,Total_Days_in_same_Status__c FROM Lead_Junction__c limit 100];
             
        }  
            
        for(Lead_Junction__c lj : ljList){
            if(lj.LeadPrevious_Status__c == 'Open' && lj.Total_Days_in_same_Status__c != null && lj.lead_sources__c == selectedSource ){
                openCount = openCount + 1;              
                TotalOpenCount = TotalOpenCount + lj.Total_Days_in_same_Status__c;              
            }
            if(lj.LeadPrevious_Status__c == 'CallBack' && lj.Total_Days_in_same_Status__c != null && lj.lead_sources__c == selectedSource ){
                CallBackCount = CallBackCount + 1;
                TotalCallBackCount = TotalCallBackCount + lj.Total_Days_in_same_Status__c;
            }
            if(lj.LeadPrevious_Status__c == 'Contacted' && lj.Total_Days_in_same_Status__c != null && lj.lead_sources__c == selectedSource ){
                ContactedCount = ContactedCount + 1;
                TotalContactedCount = TotalContactedCount + lj.Total_Days_in_same_Status__c;
            }
            if(lj.LeadPrevious_Status__c == 'Firm Enquiry' && lj.Total_Days_in_same_Status__c != null && lj.lead_sources__c == selectedSource ){
                FirmCount = FirmCount + 1;
                TotalFirmCount = TotalFirmCount + lj.Total_Days_in_same_Status__c;
            }
            if(lj.LeadPrevious_Status__c == 'Lost' && lj.Total_Days_in_same_Status__c != null  && lj.lead_sources__c == selectedSource ){
                LostCount = LostCount + 1;
                TotalLostCount = TotalLostCount + lj.Total_Days_in_same_Status__c;
            }
            if(lj.LeadPrevious_Status__c == 'Not Interested' && lj.Total_Days_in_same_Status__c != null  && lj.lead_sources__c == selectedSource ){
                NotIntrestedCount = NotIntrestedCount + 1;
                TotalNotIntrestedCount = TotalNotIntrestedCount + lj.Total_Days_in_same_Status__c;
            }
            if(lj.LeadPrevious_Status__c == 'Others' && lj.Total_Days_in_same_Status__c != null  && lj.lead_sources__c == selectedSource ){
                OthersCount = OthersCount + 1;
                TotalOthersCount = TotalOthersCount + lj.Total_Days_in_same_Status__c;
            }
            if(lj.LeadPrevious_Status__c == 'Qualified' && lj.Total_Days_in_same_Status__c != null  && lj.lead_sources__c == selectedSource ){
                QualifiedCount = QualifiedCount + 1;
                TotalQualifiedCount = TotalQualifiedCount + lj.Total_Days_in_same_Status__c;
            }
            if(lj.LeadPrevious_Status__c == 'Unqualified' && lj.Total_Days_in_same_Status__c != null  && lj.lead_sources__c == selectedSource ){
                UnqualifiedCount = UnqualifiedCount + 1;
                TotalUnqualifiedCount = TotalUnqualifiedCount + lj.Total_Days_in_same_Status__c;
            }
        
            wrapLead wl = new wrapLead();
            wl.LeadName = lj.Name;
            wl.prevStatus = lj.LeadPrevious_Status__c;
            wl.CurrStatus =lj.Lead_Current_Status__c;
            wl.leadsource = lj.lead_sources__c;
            wl.totalDays = lj.Total_Days_in_same_Status__c;
            
            wrapList.add(wl);
        }
        
        if(wrapList.size() > 0){
           if(showHideTable== false){
               showHideTable = true;
           }else if(showHideTable == true){
                   showHideTable= false;
            }
               
        }
      
        if(openCount!=0){
            openCountRecord = openCount;
        }else{
            openCountRecord = 0;
        }
        if(CallBackCount!=0){
            CallBackCountRecord = CallBackCount;
        }else{
            CallBackCountRecord = 0;
        }
        if(ContactedCount!=0){
            ContactedCountRecord = ContactedCount;
        }else{
            ContactedCountRecord = 0;
        }
        if(FirmCount!=0){
            FirmCountRecord = FirmCount;
        }else{
            FirmCountRecord = 0;
        }
        if(LostCount!=0){
            LostCountRecord = LostCount;
        }else{
            LostCountRecord = 0;
        }
        if(NotIntrestedCount!=0){
            NotIntrestedCountRecord = NotIntrestedCount;
        }else{
            NotIntrestedCountRecord =0;
        }
        if(OthersCount!=0){
            OthersCountRecord = OthersCount;
        }else{
            OthersCountRecord = 0;
        }
        if(QualifiedCount!=0){
        QualifiedCountRecord = QualifiedCount;
        }else{
            QualifiedCountRecord = 0;
        }
        if(UnqualifiedCount!=0){
        UnqualifiedCountRecord  = UnqualifiedCount;
        }else{
            UnqualifiedCountRecord = 0;
        }
        if(TotalOpenCount != 0 && openCount !=0){
            openCountWrap = (TotalOpenCount/openCount).setScale(2);
           // stagenameslist.add(openCountWrap);
            mapofstageswithdata.put('open',openCountWrap);
            mapofStatuscount.put('open',openCount); 
            system.debug('inside open  openCountWrap'+openCountWrap);
        }else{
            openCountWrap = 0;
        }
        if(TotalCallBackCount != 0 && CallBackCount !=0){
            CallBackCountWrap = (TotalCallBackCount/CallBackCount).setScale(2);
          //  stagenameslist.add(CallBackCountWrap );
            mapofstageswithdata.put('CallBack',CallBackCountWrap );
            mapofStatuscount.put('CallBack',CallBackCount);
        }else{
            CallBackCountWrap = 0;
        }
        if(TotalContactedCount != 0 && ContactedCount !=0){
            ContactedCountWrap = (TotalContactedCount/ContactedCount).setScale(2);
          //  stagenameslist.add(ContactedCountWrap );
            mapofstageswithdata.put('Contacted',ContactedCountWrap );
            mapofStatuscount.put('Contacted',ContactedCount ); 
        }else{
            ContactedCountWrap = 0;
        }
        if(TotalFirmCount != 0 && FirmCount !=0){
            FirmCountWrap = (TotalFirmCount/FirmCount).setScale(2);
         //   stagenameslist.add(FirmCountWrap );
            mapofstageswithdata.put('Firm Enquiry',FirmCountWrap );
            mapofStatuscount.put('Firm Enquiry',FirmCount); 
        }else{
            FirmCountWrap = 0;
        }
        if(TotalLostCount != 0 && LostCount !=0){
            LostCountWrap = (TotalLostCount/LostCount).setScale(2);
           // stagenameslist.add(LostCountWrap );
            mapofstageswithdata.put('Lost',LostCountWrap );
            mapofStatuscount.put('Lost',LostCount); 
        }else{
            LostCountWrap = 0;
        }
        if(TotalNotIntrestedCount != 0 && NotIntrestedCount !=0){
            NotIntrestedCountWrap = (TotalNotIntrestedCount/NotIntrestedCount).setScale(2);
           // stagenameslist.add(NotIntrestedCountWrap );
            mapofstageswithdata.put('Not Interested',NotIntrestedCountWrap );
            mapofStatuscount.put('Not Interested',NotIntrestedCount); 
        }else{
            NotIntrestedCountWrap = 0;
        }
        if(TotalOthersCount != 0 && OthersCount !=0){
            OthersCountWrap = (TotalOthersCount/OthersCount).setScale(2);
           // stagenameslist.add(OthersCountWrap );
            mapofstageswithdata.put('Others',OthersCountWrap );
            mapofStatuscount.put('Others',OthersCount); 
        }else{
            OthersCountWrap = 0;
        }
        if(TotalQualifiedCount != 0 && QualifiedCount !=0){
            QualifiedCountWrap = (TotalQualifiedCount/QualifiedCount).setScale(2);
           // stagenameslist.add(QualifiedCountWrap );
            mapofstageswithdata.put('Qualified',QualifiedCountWrap );
            mapofStatuscount.put('Qualified',QualifiedCount); 
        }else{
            QualifiedCountWrap = 0;
        }
        if(TotalUnqualifiedCount != 0 && UnqualifiedCount !=0){
            UnqualifiedCountWrap = (TotalUnqualifiedCount/UnqualifiedCount).setScale(2);         
            mapofstageswithdata.put('Unqualified',UnqualifiedCountWrap );
            mapofStatuscount.put('Unqualified',UnqualifiedCount); 
        }else{
            UnqualifiedCountWrap = 0;
        }
        
        for(String mapid:stagenamesmap.keyset()){
            if(mapofstageswithdata.containskey(mapid)){
                stagenameslist.add(mapofstageswithdata.get(mapid));
            }
            else{
                stagenameslist.add(null);
            }
        }
        
        for(String mapid:stagenamesmap.keyset()){
            if(mapofStatuscount.containskey(mapid)){
                statuscountlist.add(mapofStatuscount.get(mapid));
                system.debug('---------statuscountlist-----'+statuscountlist);

            }
            else{
                statuscountlist.add(null);
                system.debug('---------statuscountlist-----'+statuscountlist);
            }          
        }
        
       Wrapperclass w1=new Wrapperclass();
       // w1.Name='Open count'+' '+String.valueof(openCount);
        w1.data=stagenameslist;     
        wrapperlistdata.add(w1);
        
        Wrapperclass w2=new Wrapperclass();
        w2.Name='count'+' '+String.valueof(openCount);
        w2.data=statuscountlist;     
        wrapperlistdata.add(w2);
  
      system.debug('UnqualifiedCountWrap ------'+UnqualifiedCountWrap );
      stagenames=JSON.serializepretty(stagenameslist);
      AllstagesData=JSON.serializepretty(wrapperlistdata);
      system.debug('AllstagesData***'+AllstagesData);
      
         
    }
    
    public class wrapLead{
        public String LeadName{get;set;}
        public String prevStatus{get;set;}
        public String CurrStatus{get;set;}
        public String leadsource{get;set;}
        public Decimal totalDays{get;set;}
        public Decimal Avg{get;set;}
    
    }
    public class Wrapperclass{
        public list<decimal> data;
        public String Name;
        public String Name2;
        public String callBackName;
        public Wrapperclass(){
            data=new list<decimal>(); 
            Name='';
            Name2='';
            callBackName = '';
        }
    }
    
    integer i = 0;
    integer j = 1;
    integer k = 0;
    integer l = 1;
    integer m = 0;
    integer n = 1;
    integer o = 0;
    integer p = 1;
    integer q = 0;
    integer r = 1;
    integer s = 0;
    integer t = 1;
    integer u = 0;
    integer v = 1;
    integer w = 0;
    integer x = 1;
    integer a = 0;
    integer b = 1;
    integer c = 0;
    integer d = 0;
    integer e = 0;
    integer f = 1;
    integer g = 1;
    integer av = 2;
    integer ad = 2;
    integer ga = 1;
    integer avd = 2;
    integer ada = 2;
    integer gd = 1;
    integer adv = 2;
    integer afd = 2;
    integer gf = 1;
    integer avg = 2;
    integer adh = 2;
    integer gt = 1;
    integer arv = 2;
    integer adw = 2;
   
 
====================================
test class:-
 
@isTest
private class leadReportController_Test{
  @testSetup
  static void setupTestData(){
    test.startTest();
    Lead lead_Obj = new Lead(LastName = 'LastName437', Company = 'Company787', Status = 'CallBack', IsConverted = false, IsUnreadByOwner = false, Is_Neox_Lead__c = false, Function__c = 'Managing Director', Department__c = 'Purchasing', Contact_Source__c = 'info email id');
    Insert lead_Obj; 
    Lead_Junction__c lead_junction_Obj = new Lead_Junction__c(Name = 'Name381', CurrencyIsoCode = 'INR', Lead_Name__c = lead_Obj.id, LeadPrevious_Status__c = 'Open', Lead_Current_Status__c = 'CallBack', Total_Days_in_same_Status__c = 16, lead_sources__c = 'Advertisement');
    Insert lead_junction_Obj; 
    
    test.stopTest();
  }
  static testMethod void test_displayLeadTable_UseCase1(){
    List<Lead_Junction__c> lead_junction_Obj  =  [SELECT Id,Name,CurrencyIsoCode,CreatedDate,CreatedById,Lead_Name__c,LeadPrevious_Status__c,Lead_Current_Status__c,Total_Days_in_same_Status__c,lead_sources__c from Lead_Junction__c];
    System.assertEquals(true,lead_junction_Obj.size()>0);
    List<Lead> lead_Obj  =  [SELECT Company,Status,IsConverted,IsUnreadByOwner,Is_Neox_Lead__c,Function__c,Department__c,Contact_Source__c from Lead];
    System.assertEquals(true,lead_Obj.size()>0);
  test.startTest();
    leadReportController obj01 = new leadReportController();
    obj01.fromDate = Date.today();
    obj01.toDate = Date.today().addDays(3);
    obj01.showHideTable = false;
    obj01.wrapList = new List<leadReportController.wrapLead>();
    obj01.openCountRecord = 10;
    obj01.CallBackCountRecord = 10;
    obj01.ContactedCountRecord = 10;
    obj01.FirmCountRecord = 10;
    obj01.LostCountRecord = 10;
    obj01.NotIntrestedCountRecord = 10;
    obj01.OthersCountRecord = 10;
    obj01.QualifiedCountRecord = 10;
    obj01.UnqualifiedCountRecord = 10;
    obj01.openCountWrap = 10;
    obj01.CallBackCountWrap = 10;
    obj01.ContactedCountWrap = 10;
    obj01.FirmCountWrap = 10;
    obj01.LostCountWrap = 10;
    obj01.NotIntrestedCountWrap = 10;
    obj01.OthersCountWrap = 10;
    obj01.QualifiedCountWrap = 10;
    obj01.UnqualifiedCountWrap = 10;
    obj01.showhidetable2 = false;
    obj01.Flag = false;
    obj01.LeadJunList = new List<SelectOption>();
    obj01.selectedSource = 'test data';
    obj01.AllstagesData = 'test data';
    obj01.showhide = false;
  
    obj01.displayLeadTable();
    leadReportController.wrapLead obj321 = new leadReportController.wrapLead();
  test.stopTest();
    
  }
   static testMethod void test_Wrapperclass(){
    List<Lead_Junction__c> lead_junction_Obj  =  [SELECT Id,Name,CurrencyIsoCode,CreatedDate,CreatedById,Lead_Name__c,LeadPrevious_Status__c,Lead_Current_Status__c,Total_Days_in_same_Status__c,lead_sources__c from Lead_Junction__c];
    System.assertEquals(true,lead_junction_Obj.size()>0);
    List<Lead> lead_Obj  =  [SELECT Company,Status,IsConverted,IsUnreadByOwner,Is_Neox_Lead__c,Function__c,Department__c,Contact_Source__c from Lead];
    System.assertEquals(true,lead_Obj.size()>0);
    leadReportController obj01 = new leadReportController();
    obj01.fromDate = Date.today();
    obj01.toDate = Date.today();
    obj01.showHideTable = false;
    obj01.wrapList = new List<leadReportController.wrapLead>();
    obj01.openCountRecord = 10;
    obj01.CallBackCountRecord = 10;
    obj01.ContactedCountRecord = 10;
    obj01.FirmCountRecord = 10;
    obj01.LostCountRecord = 10;
    obj01.NotIntrestedCountRecord = 10;
    obj01.OthersCountRecord = 10;
    obj01.QualifiedCountRecord = 10;
    obj01.UnqualifiedCountRecord = 10;
    obj01.openCountWrap = 10;
    obj01.CallBackCountWrap = 10;
    obj01.ContactedCountWrap = 10;
    obj01.FirmCountWrap = 10;
    obj01.LostCountWrap = 10;
    obj01.NotIntrestedCountWrap = 10;
    obj01.OthersCountWrap = 10;
    obj01.QualifiedCountWrap = 10;
    obj01.UnqualifiedCountWrap = 10;
    obj01.showhidetable2 = false;
    obj01.Flag = false;
    obj01.LeadJunList = new List<SelectOption>();
    obj01.selectedSource = 'test data';
    obj01.AllstagesData = 'test data';
    obj01.showhide = false;
    
       
    leadReportController.Wrapperclass obj391 = new leadReportController.Wrapperclass();
       
  }
==========================================
Vf Page:-
 
<apex:page controller="leadReportController" showHeader="false" docType="HTML-5.0">
  <head>   
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.common-material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.material.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2018.1.221/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2018.1.221/js/kendo.all.min.js"></script>   
  </head>      
  
    <style>
          .table_design {
          margin-bottom: 41px;
          }
            .table_design td{
                white-space: nowrap;
            }
            .graph_design {
            margin:auto;
            }
            .table_design {
              border-collapse: collapse;
            }
            .table_design th, .table_design td {
               border: 1px solid #ddd;
               padding: 8px;
            }
        .table_design tr:nth-child(even){background-color: #f2f2f2;}
        .table_design tr:hover {background-color: #ddd;}
        .table_design th {
            padding-top: 12px;
            padding-bottom: 12px;
            text-align: left;
            background-color: #e28702;
            color: white;
        }
        .table_design1 {
           border-collapse:collapse;
           border:none;
           font-size:14px;
           background-color: #e28702;
           margin-bottom:30px;
        }
       .table_design1 td {
           border:none;
           padding:20px;
           text-align:left;
           background-color: #e28702;
           color:white;
       
        }
        .table_design1 input,  .table_design1 select { 
           padding: 4px 7px;
            margin: 8px 0;
            display: inline-block;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .table_design1 .btn {
           background-color: white;
           border:1px solid #e28702;
            color: #e28702;
            padding: 6px 20px;
            margin: 8px 0;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .orange_btn {
        background:#FF8939;
        border:none;
        }
        .green_btn {
        background:#B2B831;
        border:none;
        }
        .ali_center {
        margin:auto;
        width: 223px;
        margin-top: 20px;
        margin-bottom:20px;
        
        }
        .ml3 {
        margin-left:8px;
        font-size:14px;
        }
    </style>
 
    <apex:form id="myForm" >
        <table class="table_design1" border="1" align="center" width="80%" >
            <tr align="center">
                <td><b>From Date</b> &nbsp;
                    <apex:input type="date" id="fromDates" value="{!fromDate}" >
                        <apex:actionSupport event="onchange"  reRender="TableRecordId,TableRecordId2" />
                    </apex:input>
                </td>
                <td ><b>To Date</b> &nbsp;
                    <apex:input type="date" id="toDates" value="{!toDate}" >
                        <apex:actionSupport event="onchange"  reRender="TableRecordId,TableRecordId2" />
                    </apex:input>
                </td>
                <td><b>Lead Source</b> &nbsp;
                    <apex:selectList value="{!selectedSource}" size="1">
                        <apex:actionSupport event="onchange" reRender="TableRecordId,TableRecordId2"/>
                        <apex:selectOptions value="{!LeadJunList}"/>
                    </apex:selectList>
                </td>
            
            <td >
                <apex:commandButton value="Run Report" action="{!displayLeadTable}" oncomplete="createChart();" reRender="TableRecordId,TableRecordId2,kendochartid"/>
            </td>
            <td>
                <apex:commandButton value="Show/Hide Detail" action="{!displayLeadTable}" reRender="TableRecordId,TableRecordId2"/></td>
            </tr>         
        </table>
     <!-- <table class="table_design1" border="0" align="center" width="100" style="">
            <tr align="center">
                <td colspan="3">
                    <apex:commandButton value="Run Report" action="{!displayLeadTable}" oncomplete="createChart();" reRender="TableRecordId, TableRecordId2,kendochartid"/>
                </td>
            </tr>
        </table>-->
        
        <apex:outputPanel id="TableRecordId" >      
            <apex:outputPanel id="innerTableDataId" rendered="{!showHideTable}" >               
                <table class="table_design" width="80%" border="1" cellspacing="0" cellpadding="1" align="center" style=" border-bottom-style: none;font-family:Arial,Helvetica,sans-serif;font-size:10pt;color:#F08080;">
                    <tr >                       
                        <th ><apex:outputText value="Previous Status" /></th>
                        <th ><apex:outputText value="Current Status" /></th>
                        <th ><apex:outputText value="Lead Source" /></th>
                        <th ><apex:outputText value="Days to Change" /></th>                    
                    </tr>
                    <apex:repeat value="{!wrapList}" var="leadValue">
                        <tr >
                            
                            <td><apex:outputText value="{!leadValue.prevStatus}" /></td>
                            <td><apex:outputText value="{!leadValue.CurrStatus}" /></td>
                            <td><apex:outputText value="{!leadValue.leadsource}" /></td>
                            <td><apex:outputText value="{!leadValue.totalDays}" /></td>
                                                        
                        </tr>
                    </apex:repeat>
                </table>
            </apex:outputPanel>
        </apex:outputPanel>
        
        <apex:outputPanel id="TableRecordId2"  >  
             <apex:outputPanel rendered="{!showHideTable2 }" > 
              
                <table class="table_design" width="80%" border="1" cellspacing="0" cellpadding="1" align="center"  style=" border-bottom-style: none;font-family:Arial,Helvetica,sans-serif;font-size:10pt;color:#F08080;" >
                    <tr >                    
                        <th ><apex:outputText value="Previous Status" /></th>                   
                        <th ><apex:outputText value="Average Days" /></th>
                        <th ><apex:outputText value="Total Record Count" /></th>
                    </tr>
                    
                        <tr >
                            <td><apex:outputText value="Open" /></td>
                            <td><apex:outputText value="{!openCountWrap}" /></td>
                            <td><apex:outputText value="{!openCountRecord}" /></td>
                        </tr>
                        <tr>
                            <td><apex:outputText value="CallBack" /></td>
                            <td><apex:outputText value="{!CallBackCountWrap}" /></td>
                            <td><apex:outputText value="{!CallBackCountRecord}" /></td>     
                        </tr>
                        <tr >
                            <td><apex:outputText value="Contacted" /></td>
                            <td><apex:outputText value="{!ContactedCountWrap}" /></td>
                            <td><apex:outputText value="{!ContactedCountRecord}" /></td>
                        </tr>
                        <tr>
                            <td><apex:outputText value="Firm Enquiry" /></td>
                            <td><apex:outputText value="{!FirmCountWrap}" /></td>
                            <td><apex:outputText value="{!FirmCountRecord}" /></td>
                        </tr>
                        <tr >
                            <td><apex:outputText value="Lost" /></td>
                            <td><apex:outputText value="{!LostCountWrap}" /></td>
                            <td><apex:outputText value="{!LostCountRecord}" /></td>
                        </tr>
                        <tr>
                            <td><apex:outputText value="Not Interested" /></td>
                            <td><apex:outputText value="{!NotIntrestedCountWrap}" /></td>
                            <td><apex:outputText value="{!NotIntrestedCountRecord}" /></td>
                        </tr>
                        <tr >
                            <td><apex:outputText value="Others" /></td>
                            <td><apex:outputText value="{!OthersCountWrap}" /></td>
                            <td><apex:outputText value="{!OthersCountRecord}" /></td>
                        </tr>
                        <tr >
                            <td><apex:outputText value="Qualified" /></td>
                            <td><apex:outputText value="{!QualifiedCountWrap}" /></td>
                            <td><apex:outputText value="{!QualifiedCountRecord}" /></td>
                        </tr>
                        <tr >
                            <td><apex:outputText value="Unqualified" /></td>
                            <td><apex:outputText value="{!UnqualifiedCountWrap}" /></td>
                            <td><apex:outputText value="{!UnqualifiedCountRecord}" /></td>                          
                        </tr>
                    
                </table> 
               
             </apex:outputPanel>      
        </apex:outputPanel>
      
        <apex:outputPanel id="kendochartid"> <apex:outputPanel rendered="{!showhide}" >
        <!-- AllstagesData:{!AllstagesData}  showhide {!showhide} -->
           
             <script>
            function createChart() {  
                //alert('enetered');       
                $("#chart").kendoChart({
                     
                    title: {
                        text: "Lead Age Report"
                    },
                      
                    
                                          
                    seriesDefaults: {
                        type: "column",                     
                        labels: {
                        visible: true,
                        background: "transparent",  
                        position: "top",                     
                    }                                                                     
                  },  
                     legend: {
                        visible: true,
                        position: "right"
                    },
               
                   series:{!AllstagesData},
                    valueAxis: {
                       // max: 50,
                        line: {
                            visible: false
                        },
                        minorGridLines: {
                            visible: false
                        },
                        labels: {
                            rotation: "auto"
                        }
                    },
                    categoryAxis: {
                        categories: ["Open","CallBack","Contacted", "Firm Enquiry", "Lost", "Not Interested", "Others", "Qualified", "Unqualified"],
                        majorGridLines: {
                            visible: true
                        }
                    },
                    tooltip: {
                     //   visible: true,                                              
                     //  template: "#= series.callBackName#:#= series.Name#" 
                        
                    } 
                });
               
            }

            
            $(document).bind("kendo:skinChange", createChart);
            </script>
            <div id="chart" align="center" style="width: 1000px; height: 400px" class="graph_design"> </div>  
         <div class="ali_center">
         <input type="button" class="orange_btn"/><span class="ml3">Average Age</span>
         <input type="button" class="green_btn"/><span class="ml3">Record Count</span>
         </div>
        </apex:outputPanel>   
    
   </apex:outputPanel>     
        
    </apex:form>
  
</apex:page>

Tuesday 3 April 2018

Custom Lead conversion with custom Convet Button

// Code is for Custom lead conversion through custom lead convert button in Account,Contact,Opportunity

 

{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/37.0/apex.js")} 

var accnt = new sforce.SObject("Account"); 
var insertedaccountid =""; 
if({!Enquiry__c.Lead_Converted__c} == 1) 

alert('Lead is already converted'); 

else 

accnt.Name='{!Enquiry__c.Company_Name__c}'; 
if(accnt.Name !="") 

var p = new sforce.SObject('Enquiry__c'); 
p.id = "{!Enquiry__c.Id}"; 
p.Lead_Converted__c = 1; 
// p.Enquiry_Status__c = 'Converted'; 
var result = sforce.connection.update([p]); 

accnt.Id = '{!Account.Id}'; 
accnt.Name = '{!Enquiry__c.Company_Name__c}'; 
accnt.OwnerId='{!Enquiry__c.OwnerId}'; 
accnt.BillingStreet='{!Enquiry__c.Billing_Street__c}'
accnt.BillingCity='{!Enquiry__c.Billing_City__c}'; 
accnt.BillingPostalCode='{!Enquiry__c.Billing_Zip_Postal_Code__c}'; 
accnt.BillingState='{!Enquiry__c.Billing_State_Province__c}'
accnt.BillingCountry='{!Enquiry__c.Billing_Country__c}'; 
var result2 = sforce.connection.create([accnt]); 
//alert(result2[0].id); 
insertedaccountid= result2[0].id; 

var cnt= new sforce.SObject("Contact"); 
cnt.Id = '{!Contact.Id}'; 
cnt.OwnerId='{!Enquiry__c.OwnerId}'; 
cnt.AccountId=result2[0].id; 
cnt.lastName = '{!Enquiry__c.Name}'; 
cnt.MailingStreet=accnt.BillingStreet; 
cnt.MailingCity=accnt.BillingCity; 
cnt.MailingPostalCode=accnt.BillingPostalCode; 
cnt.MailingState=accnt.BillingState; 
cnt.MailingCountry=accnt.BillingCountry; 
var result = sforce.connection.create([cnt]); 

var opt= new sforce.SObject("Opportunity__c"); 
var suffixToAdd = "-CRM Implimentation"; 
opt.Id = '{!Opportunity__c.Id}'; 
opt.OwnerId='{!Enquiry__c.OwnerId}'; 
opt.Account__c= cnt.AccountId; 
opt.Name = '{!Enquiry__c.Company_Name__c}'+ suffixToAdd; 
var result = sforce.connection.create([opt]); 

if(result[0].getBoolean("success")) 

var urlis ="/"+insertedaccountid; 
//alert(urlis); 

window.location = urlis; 

else 

alert('Error : '+result); 


}

Sunday 25 March 2018

Custom Account Merging With Apex and Vfpages

/**********************************************************************************************************
* Created By    : Harshit Garg
* Created Date  : 20/Mar/2018
* Description   : This Class is for Person Account Merging. 
***********************************************************************************************************/

public class ctrlAccountMerging
{

    public string strAccSearchString {get; set;}
    public Boolean pbhide {get;set;}
    public Boolean pbhide1 {get;set;}
    public Boolean Flag{get;set;}
    public List<Account> lstAccount {get; set;}
    public List<Account> selectedAccount {get; set;}
    public Account mergeAccount {get; set;}
    public List<Account> mergeAccWithoutCheckbox {get; set;}
    public Boolean isResultDisplay {get; set;}
   
    Id devRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
     
    //  constructor
    public ctrlAccountMerging(){
        lstAccount = new List<Account>();
        isResultDisplay = false;
        pbhide=true;
        pbhide1=false;
        Flag=false;
        
    }
    
    /**********************************************************************************************************
     * Created By    : Harshit Garg
     * Created Date  : 20/Mar/2018
     * Description   : This Method is for Account searching on the basis of FirstName,LastName,Email
     /***********************************************************************************************************/
    public void SearchAccountRec(){
        isResultDisplay = true;
        pbhide=false;
        string strLikeString = '%'+strAccSearchString+'%';
        string strSOQL = 'Select id,FirstName,LastName,Flyte_Customer_Id__c,Alternate_Email__c,Alternate_Phone__c,Selected_Account__c,RecordType.name,RecordType.id,Brand__c,Phone,PersonEmail,Social_Post_URL__c from Account where (FirstName LIKE: strLikeString and RecordType.id =:devRecordTypeId) OR (LastName LIKE: strLikeString and RecordType.id =:devRecordTypeId) OR (PersonEmail LIKE: strLikeString and RecordType.id =:devRecordTypeId)';
        lstAccount = database.query(strSOQL);
           }
           
      /**********************************************************************************************************
     * Created By    : Harshit Garg
     * Created Date  : 21/Mar/2018
     * Description   : This Method is for getting selected Account from "lstAccount" List.
     /***********************************************************************************************************/     
            
    public void AccountSelectedRec(){
    
    pbhide=true;
    Flag=true;  
    selectedAccount = new List<Account>(); //List of Selected Accounts
       
       for(Account acc: lstAccount)
       {
             if(acc.Selected_Account__c==true && acc.RecordType.id==devRecordTypeId)
           {    
                acc.Selected_Account__c=false;           
                 selectedAccount.add(acc); 
           }
    
       }
    
    //This error message is for when user will not select any record
    
    if(selectedAccount.size()==0)
    {  
       pbhide=false;  
       selectedAccount.clear();
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select the records.'));
    }
    
    //This error message is for when user will select only one record
    else
  {
    if(selectedAccount.size()==1)
    {
       pbhide=false;
       selectedAccount.clear();
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select 2 Records, You have selected only 1 record'));
    }
    
    //This error message is for when user will select record above to limit
    if(selectedAccount.size()>2)
    {
       pbhide=false;
       selectedAccount.clear();
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Sorry, you can merge maximum 2 records at a time.'));
    }
    
  }
    


     /**********************************************************************************************************
     * Created By    : Harshit Garg
     * Created Date  : 23/Mar/2018
     * Description   : This Method is for Merging Master and slave Account help of "Database.Merge"
     /***********************************************************************************************************/
    
  Public void DatabaseMergeAccount()
 { 
  
      pbhide1=true;
      mergeAccount = new Account();
  
    for(Account acc1:selectedAccount) //This for loop is for getting Master from selectedAccount List which Checkbox will check
    { 
        if(acc1.Selected_Account__c==true && acc1.RecordType.id==devRecordTypeId)
        {
            mergeAccount = acc1;
        } 
    }
        //This error is Message for when user will not select any Account as a Master  
        if(mergeAccount.id == Null)
        {
            pbhide1=false;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select your Master Record'));
        }
     
     mergeAccWithoutCheckbox = new List<Account>(); //List used to getting Slave Account Record which checkbox will false 
        for(Account acc2:selectedAccount) // This for loop is for to getting slave Account
        {
            if(acc2.Selected_Account__c==false && acc2.RecordType.id==devRecordTypeId)
            {
                mergeAccWithoutCheckbox.add(acc2);
            }
        }  
        
    List<Account> AccountToMerge=new list<Account>();//This List is getting both record which we will merge
    integer Count=0; //We are intilizing Count as 0
    
    //This for loop is geeting slave which checkbox is not true and checking the count
    for(Account a :mergeAccWithoutCheckbox)
    {        
        if(Count <2 && a.RecordType.id==devRecordTypeId)
        {
          AccountToMerge.add(a);
          Count++;  
        }
        else
        {
          Count = 0;
        } 
     
    //In this if condition loop is for Merging Master and slave    
            
    if(mergeAccount.id != Null)
    {
        
        Account mergeAcc2 = [Select id,FirstName,Alternate_Email__c,Flyte_Customer_Id__c,Alternate_Phone__c,LastName,Brand__c,Phone,PersonEmail,Social_Post_URL__c from Account where id=:mergeAccount.id];
        Set<id> accIds = new Set<id>(); 
          
        for(Account a1:AccountToMerge)
        {
         accIds.add(a1.id);
        }
        
        List<Account> AccountToMerge2 = [Select id,FirstName,Alternate_Email__c,Flyte_Customer_Id__c,Alternate_Phone__c,LastName,Brand__c,Phone,PersonEmail,Social_Post_URL__c from Account where id in:accIds];
            
           for(Account acc1:[select id,FirstName,Alternate_Email__c,Flyte_Customer_Id__c,Alternate_Phone__c,LastName,Brand__c,Phone,PersonEmail,Social_Post_URL__c from Account])
         {
           
           acc1 = mergeAcc2;
           
               Integer i=0;
           if(i<AccountToMerge2.size() && acc1.PersonEmail==null)
               {
                acc1.PersonEmail = AccountToMerge2[i].PersonEmail;   
               }
               if(i<AccountToMerge2.size() && acc1.Social_Post_URL__c==null)
               {
                acc1.Social_Post_URL__c = AccountToMerge2[i].Social_Post_URL__c;   
               }
               if(i<AccountToMerge2.size() && acc1.Phone==null)
               {
                acc1.Phone = AccountToMerge2[i].Phone;   
               }
               if(i<AccountToMerge2.size() && acc1.FirstName==null)
               {
                acc1.FirstName = AccountToMerge2[i].FirstName;   
               }
               if(i<AccountToMerge2.size() && acc1.Alternate_Email__c==null)
               {
                acc1.Alternate_Email__c = AccountToMerge2[i].Alternate_Email__c;   
               }
               if(i<AccountToMerge2.size() && acc1.Alternate_Phone__c==null)
               {
                acc1.Alternate_Phone__c = AccountToMerge2[i].Alternate_Phone__c;   
               }
               if(i<AccountToMerge2.size() && acc1.Flyte_Customer_Id__c==null)
               {
                acc1.Flyte_Customer_Id__c = AccountToMerge2[i].Flyte_Customer_Id__c;   
               }
         
           } 
        //From this we are achieving Merging of Master and Slave Account   
        Database.merge(mergeAcc2,AccountToMerge2);  
     }
  }
 }
}

Vfpage

<!----------------This hole vfpage is doing Account Merging and "ctrlAccountMerging" is controller of this vfPage------------>

<apex:page controller="ctrlAccountMerging" sidebar="false" tabStyle="Account">
   
<!----------------From here Script is Start and Through this script checkbox will work like Radio button---------------------->   
<script>
function oneCheckbox(obj)
{
    if (obj.checked)
    {
        var inputs = document.getElementsByTagName("input");

        for (var i = 0; i < inputs.length; i++)
        {
            var oInput = inputs[i];
            if (oInput.type == "checkbox" && oInput.checked && oInput != obj)
            {
                oInput.checked = false; 
            }  
        }
    }

}
</script>
<!--------------------------------------------------------End Of Script-------------------------------------------------------->    
 
<!--------------------------------------------------------From here Vf Page start----------------------------------------------->    
    <apex:form id="frm">

<!-------------------------------------This PageBlock is for Searching Accounts------------------------------------------------->    
        <apex:pageBlock title="Step 1. Find the duplicate records" id="pb">
            <apex:inputtext value="{!strAccSearchString}"/>
            <apex:commandButton value="Find Accounts" action="{!SearchAccountRec}"/>        
        </apex:pageBlock>   
<!-------------------------------------This PageBlock is Select Merge Account--------------------------------------------------->            
         <apex:pageMessages id="showmsg"/>
          <apex:pageBlock rendered="{!If(lstAccount.size>0,true,false) && !(pbhide)}" id="pb2" title="Step 2. Select the records to merge">         
           <apex:pageBlockButtons location="Top">
            <apex:commandButton value="Select Merge Accounts" action="{!AccountSelectedRec}" rerender="showmsg,frm"/>       
             </apex:pageBlockButtons>
              <apex:pageBlockTable value="{!lstAccount}" var="acc">
               <apex:column >
                <apex:facet name="header">Selected Account</apex:facet>
                 <apex:inputField value="{!acc.Selected_Account__c}"/>                           
                  </apex:column>
                   <apex:column >
                    <apex:facet name="header">First Name</apex:facet>
                     <apex:outputLink value="/{!acc.FirstName}">{!acc.FirstName}</apex:outputLink>                            
                      </apex:column>
                       <apex:column >
                        <apex:facet name="header">Last Name</apex:facet>
                         <apex:outputLink value="/{!acc.LastName}">{!acc.LastName}</apex:outputLink>                            
                          </apex:column>
                           <apex:column >
                            <apex:facet name="header">Brand</apex:facet>
                             <apex:outputLink value="/{!acc.Brand__c}">{!acc.Brand__c}</apex:outputLink>                            
                              </apex:column>
                               <apex:column >
                                <apex:facet name="header">Email</apex:facet>
                               <apex:outputLink value="/{!acc.PersonEmail}">{!acc.PersonEmail}</apex:outputLink>                            
                              </apex:column>                   
                             <apex:column >
                            <apex:facet name="header">Social Post Url</apex:facet>
                           <apex:outputLink value="/{!acc.Social_Post_URL__c}">{!acc.Social_Post_URL__c}</apex:outputLink>                            
                          </apex:column>                   
                         <apex:column >
                        <apex:facet name="header">Record Type</apex:facet>
                       <apex:outputLink value="/{!acc.RecordType.Name}">{!acc.RecordType.Name}</apex:outputLink>                            
                    </apex:column>                                        
                </apex:pageBlockTable>        
            </apex:pageBlock>
           <apex:pageBlock rendered="{!If(lstAccount.size==0 && isResultDisplay == true,true,false)}" title="Search Result">            
          <apex:outputLabel value="No Result Found"></apex:outputLabel>           
         </apex:pageBlock>
    
<!----------------------------This PageBlock is getting Select Record From Step-2 and Merge the records------------------------------->  
    
            <apex:pageBlock rendered="{!If(lstAccount.size>0,true,false) && !(pbhide1)}" title="Step 3. Choose any Account as a Master record" id="pb1">          
                <apex:pageBlockButtons location="Top">          
                    <apex:commandButton value="Process To Merge" action="{!DatabaseMergeAccount}" id="b2" rendered="{!Flag}"/>
                      </apex:pageBlockButtons>      
                         <apex:pageBlockTable value="{!selectedAccount}" var="acc1" >             
                           <apex:column width="25px">
                             <apex:facet name="header">Master Account</apex:facet>
                               <apex:inputField value="{!acc1.Selected_Account__c}" onchange="oneCheckbox(this);" />
                                 </apex:column>                     
                                  <apex:column >
                                    <apex:facet name="header">First Name</apex:facet>
                                     <apex:outputLink value="/{!acc1.FirstName}">{!acc1.FirstName}</apex:outputLink>                            
                                       </apex:column>
                                        <apex:column >
                                         <apex:facet name="header">Last Name</apex:facet>
                                           <apex:outputLink value="/{!acc1.LastName}">{!acc1.LastName}</apex:outputLink>                            
                                            </apex:column>
                                             <apex:column >
                                           <apex:facet name="header">Brand</apex:facet>
                                          <apex:outputLink value="/{!acc1.Name}">{!acc1.Name}</apex:outputLink>                            
                                         </apex:column>                   
                                        <apex:column >
                                      <apex:facet name="header">Brand</apex:facet>
                                    <apex:outputLink value="/{!acc1.Brand__c}">{!acc1.Brand__c}</apex:outputLink>                            
                                  </apex:column>
                                <apex:column >
                               <apex:facet name="header">Email</apex:facet>
                             <apex:outputLink value="/{!acc1.PersonEmail}">{!acc1.PersonEmail}</apex:outputLink>                            
                           </apex:column>                       
                         <apex:column >
                        <apex:facet name="header">Social Post Url</apex:facet>
                       <apex:outputLink value="/{!acc1.Social_Post_URL__c}">{!acc1.Social_Post_URL__c}</apex:outputLink>                            
                    </apex:column>               
              </apex:pageBlockTable>
            </apex:pageBlock> 
        </apex:form>
    </apex:page>

Test Class

@isTest
private class ctrlAccountMerging_Test{
  @testSetup
  static void setupTestData(){
    test.startTest();
    Account account_Obj = new Account(LastName = 'LastName997', FirstName = 'First690', RecordTypeId = '01228000000Q0aUAAS', Brand__c = 'Allen Solly', Selected_Account__c = True);
    Insert account_Obj;
    Account account_Obj1 = new Account(LastName = 'LastName997', FirstName = 'First690', RecordTypeId = '01228000000Q0aUAAS', Brand__c = 'Allen Solly', Selected_Account__c = false);
    Insert account_Obj1; 
    test.stopTest();
  }
  static testMethod void test_SearchAccountRec_UseCase1(){
    List<Account> account_Obj  =  [SELECT LastName,FirstName,RecordType.Id,PersonEmail,Brand__c,Social_Post_URL__c,Flyte_Customer_Id__c,Alternate_Phone__c,Alternate_Email__c,Selected_Account__c from Account];
    System.assertEquals(true,account_Obj.size()>0);
    ctrlAccountMerging obj01 = new ctrlAccountMerging();
    obj01.strAccSearchString = 'test data';
    obj01.pbhide = false;
    obj01.pbhide1 = false;
    obj01.Flag = false;
    obj01.lstAccount = account_Obj;
    obj01.selectedAccount = account_Obj;
    obj01.mergeAccount = account_Obj[0];
    obj01.mergeAccWithoutCheckbox = account_Obj;
    obj01.isResultDisplay = false;
    obj01.SearchAccountRec();
  }
  static testMethod void test_AccountSelectedRec_UseCase1(){
    List<Account> account_Obj  =  [SELECT LastName,FirstName,RecordType.Id,PersonEmail,Brand__c,Social_Post_URL__c,Flyte_Customer_Id__c,Alternate_Phone__c,Alternate_Email__c,Selected_Account__c from Account];
    System.assertEquals(true,account_Obj.size()>0);
    ctrlAccountMerging obj01 = new ctrlAccountMerging();
    obj01.strAccSearchString = 'test data';
    obj01.pbhide = false;
    obj01.pbhide1 = false;
    obj01.Flag = false;
    obj01.lstAccount = account_Obj;
    obj01.selectedAccount = account_Obj;
    obj01.mergeAccount = account_Obj[0];
    obj01.mergeAccWithoutCheckbox = account_Obj;
    obj01.isResultDisplay = false;
    obj01.AccountSelectedRec();
  }
  static testMethod void test_DatabaseMergeAccount_UseCase1(){
    List<Account> account_Obj  =  [SELECT LastName,FirstName,RecordType.Id,PersonEmail,Brand__c,Social_Post_URL__c,Flyte_Customer_Id__c,Alternate_Phone__c,Alternate_Email__c,Selected_Account__c from Account];
    System.assertEquals(true,account_Obj.size()>0);
    ctrlAccountMerging obj01 = new ctrlAccountMerging();
    obj01.strAccSearchString = 'test data';
    obj01.pbhide = false;
    obj01.pbhide1 = false;
    obj01.Flag = false;
    obj01.lstAccount = account_Obj;
    obj01.selectedAccount = account_Obj;
    obj01.mergeAccount = account_Obj[0];
    obj01.mergeAccWithoutCheckbox = account_Obj;
    obj01.isResultDisplay = false;
    obj01.DatabaseMergeAccount();
  }
}

One particular lead takes how many days to change it's stage from one stage value to another

/*************** Ceated By    : Mohit Dwivedi( KVP Business Solution Pvt Ltd) . Created Date :  Purpose      : This  controller is for Lead ...