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
ApexDevApexDev 

Visualforce PDF - List of active contacts on Account

Hello! :) 

I need to create report of active records related to Account. I need extensions to show the SOQL query, because in other way I am able to see all records active and inactive. Do you have any code example that I can use, and how to show it with standard controller? :( 
VinayVinay (Salesforce Developers) 
Hi Andzela,

You can try below code snippet.
 
trigger NumberOfContacts on Account (before insert, before update) {
    if(trigger.isinsert)
        for(account a:trigger.new)
            a.Number_of_contacts__c = 0;
    else
        for(account a:[select id,(select id from contacts) from account where id in :trigger.new])
            trigger.newmap.get(a.id).Number_of_contacts__c = a.contacts.size();
            
        for(account b:[select id,(select id from contacts where Inactive__c = False) from account where id in :trigger.new])
            trigger.newmap.get(b.id).Number_of_active_contacts__c = b.contacts.size();
}

https://salesforce.stackexchange.com/questions/138455/count-the-contacts-in-the-related-list-of-account-and-display-the-contact-count

Please mark as Best Answer if above information was helpful.

Thanks,