+ Start a Discussion
ClaiborneClaiborne 

Turning Off Auto-Numbering via API and Other Data Problems

I have a situation where my client needs to change the "Master" record in a master-detail relationship. The only way to do this, of course, is to clone the old record to a new record while you change the master record. Then you delete the old record. This I can do.

 

The problem is that the old records are auto-numbered, and we want to preserve the numbers. I can do this by MANUALLY going in and turning off auto-numbering, setting the new record to have the same name as the old record, and then turning auto-numbering back on, being very careful to RESET the next number correctly.

 

As an aside, it would be really nice to expose the LAST NUMBER or NEXT NUMBER for an auto-numbered field to the api. As a work-around, I do a query sorted by Name DESC with Limit 1 to return the record with the highest number.

 

I would love to do all this in a single apex process, but the controls for auto-numbering are not exposed. So I have resigned myself turning it off and on manually, outside of the automated process.

 

But my automated process has code that wants to reset the "Name" of the record. I have tests in the code to prevent the code from executing if auto-numbering is on - you can query to see if a field is auto-numbered. But, when developing the code, you have to turn auto-numbering off because the code that contains a Save to an auto-numbered field, even if not executing, will not save.

 

The problem becomes compounded when you create test routines. If auto-numbering is off, the test routines work fine. But when you turn it back on, the test fails.

 

This means you cannot deploy to production unless you turn auto-numbering off in production during the installation. This is not too bad.

 

But the next time you want to install new code, you have to remember to turn off auto-numbering again, and then back on. If you don't, all Apex testing fails because the code that writes to the auto-number field will not even start to execute in the testing process. The code, by the way, works fine with auto-numbering on because it does not process data unless auto-numbering is off.

 

I would appreciate any suggestions from the peanut gallery.

Ispita_NavatarIspita_Navatar

I think you can use dataloader for your purpose.\

First export all the records , now turn off  autonumbering.

Make the necessary changes in the data and upload the data back.

Should hardly take 15-20 mins.

 

We have been doing all the data correction work through data loader and excel functions.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

 

ClaiborneClaiborne

I am fine using the database loader, but it not something I want my client playing with on a regular basis. That's why I wanted to automate it. Also, an automated process is safer than using database loader because of all the manual operations involved.

 

I also would love to be able to turn off autonumbering when running tests. Every time I update my client's apex code, it runs all the tests, which create a lot of temporary records. The records are obviously erased after the test, but the auto-numbering sequences do not reset to where they were before the testing started. Missing numbers in a sequence concern my client, but there is nothing I can do.

Manoj_Manoj_

Claiborne,

 

I am faced with similar issues in an implementation. Did you find a solution to this problem yet? If yes can you please help me out as well.

 

Thanks,

Manoj

ClaiborneClaiborne

Sorry. Nothing available except manual manipulation. And I have not seen increased api access to the auto-numbering anywhere on the "road map."