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
Tarun KaushikTarun Kaushik 

How to get a count on number of accounts

HI
I have created a custom field on Account object as "No of records" and I want to update all number of reocrds in that field.
Like if a new account is created then this new firld should increasd accordingly.
So how can I approach to make this customization
 
SonamSonam (Salesforce Developers) 
Hey Tarun, if I understand this correctly:
Account has a custom field: No of records and this gets updated with each new account record created.

so Account 1 created :  No of records =1
Account 2 created: No of records =2 which is updated on Account 1 and Account 2
Account 3 created : No of records =3 which is updated on Account 1, Account 2 and Account 3 and so on...
Is that correct?

If you wish to simply keep a count of the records,  - you can even do this using an auto number such the latest record created will have the no. of records.
ShashankShashank (Salesforce Developers) 
You can just use a SOQL query to find the number of account records in an apex trigger and update it on an account field.

integer count = [select count() from account];
system.debug(count);