+ Start a Discussion
Devaraj 7Devaraj 7 

how to show contact phone numbers with the count in vf page

phone                  count
995566                 2
995566                 2
123456                 1
 
Maharajan CMaharajan C
Hi Dinesh,

Please try the below codes:

And Click button based on Phone in the Page it will give the result for you:

VF Page:

<apex:page controller="Contactup">
    <apex:form >
        <apex:pageblock title="Duplicate Contacts">
            <apex:pageBlockButtons >
                <apex:commandButton value="based on phone" action="{!getbyphone}"/>
            </apex:pageBlockButtons>
            <apex:PageBlockTable value="{!ac}" var="a"  rendered="{!bLead}">
                <apex:Column value="{!a.name}"/>
                <apex:Column value="{!a.phone}"/> 
            </apex:PageBlockTable>
            <apex:PageBlockTable value="{!ac1}" var="a"  rendered="{!bphone}">
                <apex:Column value="{!a['Phone']}"/>
                <apex:Column value="{!a['count1']}"/> 
            </apex:PageBlockTable>               
        </apex:pageblock>
    </apex:form>
</apex:page>

Class:

public class Contactup {

    public List<Contact>ac{get;set;}
    public List<AggregateResult> ac1 {get; set;}
    public Boolean bphone {get; set;} 
    public Boolean bLead {get; set;}
    
    public Contactup(){
        bphone = false;
        bLead = true;
        ac =[SELECT name,Phone FROM contact where Phone!=Null];
    }
    public void getbyphone(){
        bphone = true;
        bLead = false;
        ac1=[SELECT Phone,count(Id) count1 FROM lead GROUP BY Phone HAVING count(Id)>=1];
    }
     
}

Let me know if it works or not!!!

If it works mark this as a best answer!!!

Thanks,
​Raj