How to delete an Apex class in production?

1,398 views
Skip to first unread message

proto...@gmail.com

unread,
Apr 11, 2016, 10:39:45 AM4/11/16
to Illuminated Cloud Q&A
In the past (when I used the Eclipse Force.com IDE), to delete a no-longer-needed Apex class in production I would do the following:

1. Replace contents of class with //DELETED
2. Make everything work, remove old unit tests, etc
3. Deploy to production via changeset
4. Open connection to production org in the IDE
5. Change the Status in the meta file for the class to Deleted
6. Save

And voila, it would disappear from the production org.

I'm trying to do the same thing via Illuminated Cloud, but it's failing on step 6 -- trying to save the updated meta file in the production org just cranks on "Deploying MyFile.cls-meta to Production" until I kill it.

I've spent the morning beating my head against the wall on this, as I'm sure someone must have figured this out... thanks in advance for your help!

- mo

Scott

unread,
Apr 11, 2016, 11:31:48 AM4/11/16
to Illuminated Cloud Q&A
Are you using the Tooling API to deploy?  That wouldn't send over the updated metadata status of Deleted.  You might try changing to the Metadata API using Settings>Illuminated Cloud>Validation & Deployment by setting the Apex value to the Metadata API.  Please let me know whether that helps or not.

Regards,
Scott Wells

Scott

unread,
Apr 11, 2016, 12:49:11 PM4/11/16
to Illuminated Cloud Q&A
One other note on this...you can explicitly delete metadata from Illuminated Cloud, either by deleting the local file and confirming the prompt to propagate the delete to the server, or by performing an explicit delete operation (Build>Illuminated Cloud>Delete Metadata from the menu bar or Illuminated Cloud>Delete Metadata from the context menu).  Either way it deploys a destructive changes request to the server for the selected metadata.
Message has been deleted

Christian Anderson

unread,
May 17, 2016, 1:04:03 AM5/17/16
to Illuminated Cloud Q&A
I've tried using the Delete Metadata option several times.  Also tried changing from Tooling to Metadata API.  But whenever I try to delete from my production org I get the following error:
INVALID_OPERATION: purgeOnDelete option can only be used on a non-active org.

Christian Anderson

unread,
May 17, 2016, 12:35:33 PM5/17/16
to Illuminated Cloud Q&A
Just as outlined in original post, I was able to update the Metadata status to Deleted for the files I wanted to delete in production.  Then using IC I deployed the class to production and it deleted with no problems.

knu...@gmail.com

unread,
Jan 16, 2017, 7:14:35 PM1/16/17
to Illuminated Cloud Q&A
Having problems deleting a class from production.  Could have sworn I've done it before with IC, but struggling now.
Tried with both Tooling and Metadata APIs, forcing a save of metadata file with <status>Deleted</status>, ..etc.

Scott would you mind posting a definitive procedure for how it should be performed using IC?

thanks,
Dennis

Scott

unread,
Jan 16, 2017, 7:41:40 PM1/16/17
to Illuminated Cloud Q&A
Dennis, I think if you set the metadata status to Deleted and then use the metadata API to deploy it (i.e., disable the tooling API for at least that metadata type), it should do what you want.  You could also try using the Delete Metadata action which deploys destructive changes for the selected metadata, but I'm pretty sure that's going to lead to the INVALID_OPERATION cited earlier in this thread.

If that fails please let me know what kind of error message(s) you're getting from the server in response.

Regards,
Scott

Dennis Wilson

unread,
Jan 17, 2017, 11:42:37 AM1/17/17
to Illuminated Cloud Q&A
After a series of steps, involving re-retrieving, re-refreshing and re-deploying got it work.  Not exactly sure what finally made it go through.  I kept looking in the IC log for any useful entries, but didn't see anything.

Only thing different about the ultimately successful deploy was it showed running all unit tests.  On previous unsuccessful attempts it was not showing any test runs.

I think one thing that may be contributing is I had 5 different projects up/running at same time.  And the Tooling/Metadata API setting appears to be a global.

Next time I need to do this I'll make sure only a single instance is running...

Thanks!

Scott

unread,
Jan 17, 2017, 1:14:04 PM1/17/17
to Illuminated Cloud Q&A
Interesting.  I'm not sure why retrieve/refresh would come into play here.  As for the Tooling/Metadata API settings, yes, it's application-level, not project or module-level.  However, it shouldn't matter whether you have more than one project open as it should be using that setting to deploy for that project/module to the respective connection.

Not saying there's not a bug here...that's very possible...just commenting on how it's intended to work.  If you do see this happen again in the future, please let me know ASAP so we can get some logs and see what's going on.

Regards,
Scott

akip...@gmail.com

unread,
Feb 27, 2017, 11:00:21 AM2/27/17
to Illuminated Cloud Q&A
Excuse me. please tell me.
Change the class (xxx.cls - meta.xml) to be deleted to <status> Deleted </ status>
Select xxx.cls and xxx.cls-meta.xml, right click
Deploy All Metadata .. was executed.

I deployed it as a production destination, but it will not be deleted over and over. What should I do?

Illuminated Cloud Version is1.7.8.5

proto...@gmail.com

unread,
Feb 27, 2017, 11:11:33 AM2/27/17
to Illuminated Cloud Q&A
Note that when you deploy it, it will run as a production deployment -- i.e. it will run all of your unit tests. If you have a lot of unit tests, it could take a long time to execute. You can view/track the deployment in the usual way via the Salesforce UI.

Also, I don't use Deploy All Metadata to push it out, I just save the file, I have the project set to deploy on save (IntelliJ > Preferences > Languages & Frameworks > Illuminated Cloud > check "Deploy on save".

There's also the settings where you can tell it which API to use (Metadata vs Tooling), but I can't find where that is (I generally find it difficult to track down the various Illuminated Cloud config screens)... if you can find it then you may want to play with that as well.

Hope some of that helps!

- mo

Scott

unread,
Feb 27, 2017, 11:22:13 AM2/27/17
to Illuminated Cloud Q&A
FYI, I've tried to simplify access to the IC config screens.  Under the Illuminated Cloud menu (both pull-down under Build and context) are actions to open the application, project, and module-level settings with assigned keystrokes for quick access:


Hopefully settings are WAY more streamlined in recent builds.  Application-level settings include license key entry, connection config, and deployment config.  Project-level settings are where you choose connections for your local project.  Module-level settings are where you configure the metadata subscription and deployment/retrieval substitution rules.

Regards,
Scott

proto...@gmail.com

unread,
Feb 27, 2017, 11:43:20 AM2/27/17
to Illuminated Cloud Q&A
Scott that is AWESOME. I just updated my install and see all of that there now. Thanks so much for that, it will make config so much easier!

akip...@gmail.com

unread,
Feb 27, 2017, 11:45:20 AM2/27/17
to Illuminated Cloud Q&A
Thank you for answering. However, it can not be deleted yet.

Scott

unread,
Feb 27, 2017, 12:06:14 PM2/27/17
to Illuminated Cloud Q&A
Unfortunately I don't have test access to a production org right now to debug the behavior directly, but let's get a debug log and see what it says if you don't mind.  Please add the following under Help>Debug Log Settings:

#com.illuminatedcloud.intellij.builder.ForceComBuilder
#com.illuminatedcloud.intellij.builder.ForceComMetadataApiDeployer
#com.illuminatedcloud.intellij.builder.ForceComToolingApiDeployer

Run the deployment and then grab your idea.log using Help>Show Log in Explorer/Finder and send it over to me at sup...@illuminatedcloud.com.  I'll take a look and see if anything stands out.

Best regards,
Scott

akip...@gmail.com

unread,
Feb 27, 2017, 7:41:08 PM2/27/17
to Illuminated Cloud Q&A
Thank you for your kindness
I'm sorry. Logs can not be sent due to various circumstances.

However, I do not understand why,
There are multiple classes to delete,
If you do the same operation several times,
I found out what files were deleted.

akip...@gmail.com

unread,
Feb 27, 2017, 7:45:47 PM2/27/17
to Illuminated Cloud Q&A

Application setting is below.


akip...@gmail.com

unread,
Feb 28, 2017, 1:59:34 AM2/28/17
to Illuminated Cloud Q&A
solved.
Firstly, we had to delete the interlocking relationship of the class to be deployed.
So, first of all, please empty the contents and deploy. Then delete it with <status> Deleted </ status>.

Scott

unread,
Feb 28, 2017, 9:26:40 AM2/28/17
to Illuminated Cloud Q&A
Glad you were able to get it resolved and thank you for sharing the details.

Regards,
Scott
Reply all
Reply to author
Forward
0 new messages