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
wlevywlevy 

Change custom object name

I discovered that someone created a custom object in our project using the wrong name. When I try to change the Object Name I get a number of validation errors because the current object name is referenced in several places (a page, a class, and a trigger). However, the system won’t let me change the referenced name in the offending apex code files – it’s a Catch 22.

 

I imagine this scenario is not uncommon. How does one go about changing an object name that’s already referenced in code? Scratching my head over this one!

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I usually find I end up commenting out the apex code, changing the name then re-instating it.  If there's code striped all over the place, I create a new object based on the old one then clone all the fields in via the Force.com IDE and change the code after that using global search/replace. 

All Answers

bob_buzzardbob_buzzard

I usually find I end up commenting out the apex code, changing the name then re-instating it.  If there's code striped all over the place, I create a new object based on the old one then clone all the fields in via the Force.com IDE and change the code after that using global search/replace. 

This was selected as the best answer
sfdcfoxsfdcfox

You have to change both the reference AND the code at the same time. How? Just use the Metadata Toolkit or the Force.com IDE. Change all of the affected files, and then build the project. Assuming no unresolved references remain, the system will update all the changes at once. Or, like Bob said, you can just comment out the code pieces. Either way, you're in for the long haul; there really isn't a one-click means of fixing this.

wlevywlevy

Yuck. I was afraid of that... it would be so nice to be able to either automatically rename references to renamed objects or to be able to turn off validation temporarily.

 

Thanks for your help.