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
Chenna4a2Chenna4a2 

Auto Number

Hi All,

 

I need to  populate Account name as ACC + year created + 9 digits( autonumber)

 

Example: Acc- 2013 - 100000001.......

 

Can anyone help me out ???? Thanks in Advance....

Best Answer chosen by Admin (Salesforce Developers) 
Dhaval PanchalDhaval Panchal

You can also implement this in below way.

1. Create new vf page with standard controller "Account". (see below code for page and controller)

 

VF Page:

<apex:page StandardController="Account" extensions="AccountNewOverride" action="{!goToStandardPage}">
</apex:page>

 

Controller:

public class AccountNewOverride {
    public AccountNewOverride(ApexPages.StandardController controller) {
        
    }
    Public PageReference goToStandardPage(){
        string retURL = ApexPages.CurrentPage().getParameters().get('retURL');
        string ent = ApexPages.CurrentPage().getParameters().get('ent');
        string URL='/001/e?';
        URL += 'retURL=' + retURL;
        URL += '&ent=' + ent;
        /* If you have account record types then add below lines otherwise do not 
add following two lines */
string recordType =  ApexPages.CurrentPage().getParameters().get('RecordType');
URL += '&RecordType=' + RecordType;
List<AggregateResult> lstAg = [Select count(Id) cnt From Account]; Integer intCount = 0; if(lstAg.size()>0){ intCount = Integer.valueOf(lstAg[0].get('cnt')); } /*You can modigy getDigit function in your way*/ String accountName = 'Acc-' + System.Now().Year() + '-' + getDigit(intCount); /* acc2 is a control id of Account Name of Account new standard page. You can get this control id using firebug */ URL += '&acc2=' + accountName; URL += '&nooverride=1'; PageReference P = new PageReference(URL); P.SetRedirect(true); return P; } Public String getDigit(Integer cnt){ String digit = String.valueOf(cnt + 1); while(digit.length()<9){ digit = '0' + digit; } return digit; } }

 
2. Now go to Account -> Buttons and Link section.
3. Click on new standard button.
4. Override this button using this new vf page.

All Answers

SoleesSolees

Hi you could do this but only if the year is static.  

 

So every year you have to change the 2013 to 2014... 2015 and so on.

 

 

 

The other thing you could do, is leave the Auto Number as it is, create a fórmula field using the 'Acc-Year(Now())-Name'

 

And another thing is to have a simple number field that you increment with a workflow everytime a record is created.

 

Or maybe use a trigger to increment this number.

Dhaval PanchalDhaval Panchal

You can also implement this in below way.

1. Create new vf page with standard controller "Account". (see below code for page and controller)

 

VF Page:

<apex:page StandardController="Account" extensions="AccountNewOverride" action="{!goToStandardPage}">
</apex:page>

 

Controller:

public class AccountNewOverride {
    public AccountNewOverride(ApexPages.StandardController controller) {
        
    }
    Public PageReference goToStandardPage(){
        string retURL = ApexPages.CurrentPage().getParameters().get('retURL');
        string ent = ApexPages.CurrentPage().getParameters().get('ent');
        string URL='/001/e?';
        URL += 'retURL=' + retURL;
        URL += '&ent=' + ent;
        /* If you have account record types then add below lines otherwise do not 
add following two lines */
string recordType =  ApexPages.CurrentPage().getParameters().get('RecordType');
URL += '&RecordType=' + RecordType;
List<AggregateResult> lstAg = [Select count(Id) cnt From Account]; Integer intCount = 0; if(lstAg.size()>0){ intCount = Integer.valueOf(lstAg[0].get('cnt')); } /*You can modigy getDigit function in your way*/ String accountName = 'Acc-' + System.Now().Year() + '-' + getDigit(intCount); /* acc2 is a control id of Account Name of Account new standard page. You can get this control id using firebug */ URL += '&acc2=' + accountName; URL += '&nooverride=1'; PageReference P = new PageReference(URL); P.SetRedirect(true); return P; } Public String getDigit(Integer cnt){ String digit = String.valueOf(cnt + 1); while(digit.length()<9){ digit = '0' + digit; } return digit; } }

 
2. Now go to Account -> Buttons and Link section.
3. Click on new standard button.
4. Override this button using this new vf page.

This was selected as the best answer
Chenna4a2Chenna4a2

Hi,

 

This resolves my issue but i want to do on standard page as Account Name is standard field??

 

Can we do on standard fields ???

Dhaval PanchalDhaval Panchal

Yes,
My example is on standard field account name.