function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Counting Records

I need to count records as they are created and base that count on a field in a separate object.  Sales records are used to capture details of each sale.  Sales Tracker records are used to capture the count for a certain sales person who is linked to both records as a contact through a lookup.  So when a Sales record is created it searches for the Sales Tracker record with the same sales person listed in the lookup to the contact object.  I need to be able to add the id of the Sales Tracker record to the Sales record, pull the sales count from the Sales Tracker record, increment it by one, write it to the Sales record and Sales Tracker record.  I don't even know where to start so any help would be greatly appreciated.


Here i am giving one Example to you..


Counting the Duplicate records in one object..


Create VF page and like this we can start ...


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



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(;
            if(count != null)
                count = 1;
            data.put(, count);






Thank you for your reply, but I am not sure we are on the same page.  The process is not related to duplicate records.  Basically when an Opportunity is closed/won a Sales__c record is created with information from the Opportunity to include a lookup to a Contact.  At that point I would like to search for a Sales_Tracker__c record that is acitve (checkbox) and has that same Contact in a lookup.  Once that is matched, I would like to capture the ID of the Sales_Tracker__c record and put it in a lookup on the Sales__c record.  I would also like to pull the Policy Count on the Sales_Tracker__c record, increment that by one and write it back to the Sales_Tracker__c record and the Sales__c record that originally fired the trigger.


The idea is to capture the current policy count on the new Sales__c record related to the specific Contact on the Sales__c record.


Thanks again!


Write a trigger...

Pull all those records based on conditions..

And you can do whatever you want..

Try once send your code and full requirement ... we will help you regarding this..