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
SFDC BeginerSFDC Beginer 

Display the account count

Hi everyone,
I created one custom filed accountcount and when ever new account created, count is reflected in that filed.
now requirement is like " need to display the message when the record is created and need to display the message like this the 48th record".
below is the code for account count, and i want to display the message.could anyone please sugggest me how to achieve this?

public class CountAccount {
    public static void accountscount(List<Account> accs)
    {
     Decimal CountOfAccount=[Select COUNT() From     Account];
    for(Account a:accs)
    {
       a.AccountCount__c=CountOfAccount+1;
       CountOfAccount=a.AccountCount__c;
    }
       
    }

}
 
Abdul KhatriAbdul Khatri
Please check the below link it will help you to generate th, rd etc for the given number and then you concatenate with the "record" string

https://salesforce.stackexchange.com/questions/41787/how-can-i-format-a-day-from-a-date-as-2nd-intead-of-2-or-3rd-instead-of-3
GauravendraGauravendra
Hi SFDC Beginner,

You can create a after trigger on account object. From there you can call your apex method. Inside the apex method, query to get the count of total account record. Get the no of recods in apex method by passing the parameter Trigger.New from trigger to apex method. Add the no of newly added account to current count of record. 

Query all account. Update the custom field Count__c with the new value for all the records.

​Hope this helps.
SFDC BeginerSFDC Beginer
Hi Gauvavendra,
thanks for the logic
the code above I posted is perfectly working.. what i want to know is like when the new account record is created i just want to display the message " this is the account number 56".

Abdul- i will look in to that, thanks for help
v varaprasadv varaprasad
Hi,

Please check once sample code : 
 
decimal count = 52;
string counter = 'this is the account number' +(count+1);

system.debug('==counter=='+counter);



public class CountAccount {
    public static void accountscount(List<Account> accs)
    {
     Decimal CountOfAccount=[Select COUNT() From     Account];
    for(Account a:accs)
    {
       a.AccountCount__c= 'this is the account number'+(CountOfAccount+1);
       CountOfAccount=a.AccountCount__c;
    }
       
    }

}



Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
 
Abdul KhatriAbdul Khatri
@SFDC Beginer I thought you need th, rd like 45th, 23rd at the end of each number but with your later it doesn't look like that. I proposed my solution based on that otherwise getting the later one shouldn't be that hard.
Abdul KhatriAbdul Khatri
Hey SFDC Beginner

Were you able to get this resolved?