Total Number of Contacts in Account

Last Updated Days

Total Number of Contacts in Account : Every Account have contacts and it can be one or many but we can’t get total number of Contacts in Account and easy to count number of Contacts in Account.

It’s custom button with JavaScript. Below are steps for it.

Step 1: Click Setup

Step 2: Click Accounts

Step 3: Create Text Field “Total Contacts

Step 4: Click Buttons, Links, and Actions

Contact Contact

Step 5: Write JavaScript

Contact Contact Java Script

JavaScript 

{!REQUIRESCRIPT(‘/soap/ajax/28.0/connection.js’)}
var o = new sforce.SObject(“Account”);
o.id= “{!Account.Id}”;
var aid = “{!Account.Id}”;
var qr = sforce.connection.query(“Select ID,Name,Email from Contact where AccountId='” + aid + “‘”);
var records = qr.getArray(“records”).length;
o.Total_Contacts__c= records ;
sforce.connection.update([o]);
window.location.reload();

Step 6: Add “Total Contacts” in Account Page Layout

Step 7: Add “Contact Count” Button in Account Page Layout

Account Page Count Contact

Final Step : Click on “Contact Count”

Contact Count

 

Leave a Reply