Wednesday, 23 January 2013

Counting The Duplicate Records


Hi all, the scenario is just count the duplicate records. How many times that record is arrived. 
we are displaying in VF page..

<apex:page controller="test4">
 <apex:pageblock title="Map Usage On VF">
     <apex:pageBlockTable value="{!data}" var="d">
         <apex:column headerValue="Account Name">
             {!d}
         </apex:column>
         <apex:column headerValue="Duplicate Count">
             {!data[d]}
         </apex:column>
     </apex:pageBlockTable>
 </apex:pageblock>
</apex:page>



public class test4{
   
    public map<string,integer> data {get;set;}
    public test4(){
        data = new map<string,integer>();
        for(Account acc: [Select Id, Name, (Select Id, Name, Email from Contacts), Phone from Account]){
            integer count = data.get(acc.name);
            if(count != null)
                count++;
            else
                count = 1;
            data.put(acc.name, count);
        }
    }
}



No comments:

Post a Comment