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
Devendra@SFDCDevendra@SFDC 

Requirement to Achieve AutoNumber functionality

 

Hello,

 

Managed Package Functionality:


I am developing on managed package app which will be used by different customer.In this app, I am using one object called Job. I need to use one field as Job Number. This Job Number field is populated based on Customer's demand.

 

For example,
Customer 1 has requirement to populate it as YYYY_MM_AutonumberValue.

 

Customer 2 has requirement to populate it as MM_YYYY_AutonumberValue.

 

Customer 3 has requirement to populate it as only AutonumberValue.

 

Customer needs to have ability to to provide different criteria to set this value.

 

I also want to use this field on visualforce pages, apex code.

 

What would be suggestion to handle such scenarios?

 

 

Thanks,
Devendra

Best Answer chosen by Admin (Salesforce Developers) 
b-Forceb-Force

There are several options to store these criteras,

You can store those in some custom object, best ways to store those value in Custom setting or Custom Label.

 

If you store them in Custom setting [These acts similar to custom object ]

you can fetch them in trigger code and update object Name value as per your requirement.

 

You need to do 

 

Keep Name as text

Add one more autonumber field on object 

By some trigger,  Name = Autonumber + your custom logic

 

Thanks,

bForce

All Answers

WizradWizrad

Don't make the Name field an auto-number, keep it as text.

 

Write a trigger that picks up on this criteria and names the record appropriately.

Devendra@SFDCDevendra@SFDC

 

Wizrad, Thanks for the reply!

 

These criterias can be different for different customer. The criteria is not fixed.

 

How to handle those criterias as well?

 

Does Custom settings helps to do this?

 

Thanks,

Devendra

b-Forceb-Force

There are several options to store these criteras,

You can store those in some custom object, best ways to store those value in Custom setting or Custom Label.

 

If you store them in Custom setting [These acts similar to custom object ]

you can fetch them in trigger code and update object Name value as per your requirement.

 

You need to do 

 

Keep Name as text

Add one more autonumber field on object 

By some trigger,  Name = Autonumber + your custom logic

 

Thanks,

bForce

This was selected as the best answer
Devendra@SFDCDevendra@SFDC

 Thanks b-Force,

 

--------------------------------------------------------------------------------------------------------------------------------

Keep Name as text

Add one more autonumber field on object 

By some trigger,  Name = Autonumber + your custom logic

--------------------------------------------------------------------------------------------------------------------------------

 

I did the same what you mentioned.

 

Instead of using extra AutoNumber field on object, Can we fetch number from last record, increment that number and use it for next record?

Will this work?

 

Thanks,

Devendra

 

 

b-Forceb-Force

Yes you can do this.

 

 

Thanks,

bForce

Devendra@SFDCDevendra@SFDC

 

Hi b-Force,

 

I did the same, Thanks a lot..!!

 

Cheers,

Devendra