Monday 18 March 2013

Display Duplicate Records count

Here We have a scenario.

In Account object we have lot of records. If we need to know , how many  records with the same name present in your object.

Record Name and that record count..

Please look at this code.

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>


Controller
------------

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